我从文件中读取一行:
KatalogObrazków 1 32
意味着我应该在以下位置查找数据:
C:\Users\NAME_OF_THE_USER/KatalogObrazków
所以我这样做,但发生了可怕的事情。在splitLine[0]
我有一个单词"KatalogObrazków"
但是计算机说"KatalogObrazków".equals(splitLine[0])
为假,分割后没有留下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();
输出:
KatalogObrazków
false
false
C:\Users\R/KatalogObrazków
编辑:
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
答案 0 :(得分:6)