我在Eclipse中遇到了一個非常奇怪的問題,我不確定它是一個錯誤還是一些設置錯誤。Fedora Eclipse - io流中的空字符
我使用的Fedora的Eclipse在Fedora 14
在Eclipse文本編輯器中打開帶有空字符的文件,當我第一次注意到這個問題。在到達第一個空字符後,不再顯示其他字符。此外,如果文件包含空行後的新行,則null和newline之間的所有內容都不顯示,但在換行符後正確恢復。
例子:
#A file with values:
66 6F 6F 00 62 61 72
#Displays:
foo
#When it should read something like:
fooNULLbar
這不會比一個小麻煩更多,如果運行Eclipse的一個程序時,它並沒有擴展到I/O。如果我嘗試使用InputStream或Reader讀取上一個示例中的文件,則會在null之前導致文件結束。
例子:
# File: test
66 6F 6F 00 62 61 72
# File: Test.java
import java.io.File;
import java.io.FileInputStream;
public class Test {
public static void main(String[] args) {
try {
File file = new File("test");
FileInputStream in = new FileInputStream(file);
int b;
while ((b = in.read()) != -1) {
System.out.print((char) b);
}
in.close();
} catch (Exception e) {
System.err.println(e.getMessage());
}
}
}
# Produces output to Eclipse console:
foo
# While when run from command line, it produces:
fooNULLbar
當我打開這些文件或運行Eclipse之外這些程序,一切正常,包括在Eclipse編譯的程序。
我碰到這個而谷歌搜索的問題,但我不知道這是否是同一個問題:https://bugs.eclipse.org/bugs/show_bug.cgi?id=283231
預先感謝所有幫助。
如果用'\ 0'替換'null'字符會怎麼樣? – Bhushan 2011-05-18 00:38:57
中的空字符是文件,只是0x00的字節值\ 0。 – jjg4 2011-05-18 01:00:29