我從.txt文件本readed:java中,在開始打印將「空」
<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM "/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
<allow-access-from domain="*" to-ports="*" />
</cross-domain-policy>
但閱讀它,然後outputing後,我得到這個:
null<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM "/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
<allow-access-from domain="*" to-ports="*" />
</cross-domain-policy>
零開頭,這是方法:
public class Filer {
private static String str;
public static String read(String file) {
BufferedReader br = null;
try {
String sCurrentLine;
br = new BufferedReader(new FileReader(file));
while ((sCurrentLine = br.readLine()) != null) {
str += sCurrentLine;
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (br != null)br.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
return str;
}
}
返回的字符串其被outputed
我試圖通過str.indexOf("null");
或str.indexOf("\0");
檢查字符串,但我得-1
就如何解決這一問題的任何想法?
感謝您對本信息,我'學習這種東西) – user2507316
@ user2507316:看我的編輯甚至更多... –
chosed這個答案是接受全建設者例子,再次感謝你 – user2507316