【发布时间】:2015-01-13 02:03:59
【问题描述】:
所以我尝试运行我的应用程序,它在终端中给了我这个警告:
Jan 12, 2015 8:57:00 PM com.sun.javafx.tk.quantum.PrismImageLoader2$PrismLoadListener imageLoadWarning
WARNING: null
Jan 12, 2015 8:57:00 PM com.sun.javafx.tk.quantum.PrismImageLoader2$PrismLoadListener imageLoadWarning
WARNING: Corrupt JPEG data: premature end of data segment`
它将在/Dir 中播放两首歌曲(共六首),然后意外停止。
如何让它不抛出这个警告?以及如何让它遍历整个目录?
public void getMusicDirectory() {
try {
File folder = new File("./Dir");
File[] contents = folder.listFiles();
for (int i = 0; i < contents.length; i++) {
String name = contents[i].getName();
//System.out.println(name);
if (name.indexOf(".mp3") == -1) {
continue;
}
//System.out.println(name + "continuing");
FileInputStream file = new FileInputStream(contents[i]);
int size = (int)contents[i].length();
//System.out.println(size);
file.skip(size - 128);
byte[] last128 = new byte[128];
file.read(last128);
String id3 = new String(last128);
String tag = id3.substring(0, 3);
if (tag.equals("TAG")) {
songsDir.add(new Song((new MediaPlayer(new Media(contents[i].toURI().toString()))),id3));
file.close();
} else
file.close();
}
} catch (Exception e) {
System.out.println("Error -- " + e.toString());
}
}
这就是我正在使用的代码。我不明白为什么它不会遍历所有文件,或者为什么会触发警告。
【问题讨论】:
-
一些问题: 1. 它总是在同一个文件上失败吗? (例如,尝试仅加载失败的单个文件。) 2. 是否有关于错误的更多详细信息(例如堆栈跟踪等)? 3. 你的
Song类是否在某处加载图像?