我从文件中读取了一行:
KatalogObrazków 1 32
意味着我应该在以下位置查找数据:
C:\Users\NAME_OF_THE_USER/KatalogObrazków
所以我就这么做了,但可怕的事情正在发生。在splitLine[0]
我有一句话"KatalogObrazków"
但随后计算机说"KatalogObrazków".equals(splitLine[0])
为 false,周围没有空白splitLine[0]
分割线后左侧。请看下面的代码。
BufferedReader br = new BufferedReader(new FileReader(path));
String line;
String[] splitLine;
if ((line = br.readLine()) != null) {
splitLine = line.split(" ");
System.out.println(splitLine[0]);//1st line of output
System.out.println("KatalogObrazków".equals(splitLine[0]));//these are not EQUAL!!!!!??? WHY?
imageDirectoryPath = System.getProperty("user.home")+"/" + splitLine[0];
System.out.println(new File(imageDirectoryPath).exists());
delay = Integer.parseInt(splitLine[1]);
fontSize = Integer.parseInt(splitLine[2]);
}
br.close();
Output:
KatalogObrazków
false
false
C:\Users\R/KatalogObrazków
EDIT:
System.out.println();
for (char c : splitLine[0].toCharArray())
System.out.print((int) c + " ");
System.out.println();
for (char c : "KatalogObrazków".toCharArray())
System.out.print((int) c + " ");
System.out.println();
GOT ME:
65279 75 97 116 97 108 111 103 79 98 114 97 122 107 243 119
75 97 116 97 108 111 103 79 98 114 97 122 107 243 119
您可能在文件开头遇到过 UTF-BOM。
http://en.wikipedia.org/wiki/Byte_order_mark
它是不可见的,因为大多数编辑器都会隐藏它。很邪恶吧?
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)