可以说我有一个字符串=“你好”。我如何打开一个文本文件并检查该文本文件中是否存在你好?该文本文件的在分隔文本中搜索字符串文件
内容:
hello:man:yeah
我尝试使用下面的代码。它是只读文件的第一行吗?我需要它来检查所有行,看看你是否存在,然后如果是这样,请从中取出“man”。
try {
BufferedReader in = new BufferedReader(new FileReader("hello.txt"));
String str;
while ((str = in.readLine()) != null) {
System.out.println(str);
}
} catch (IOException e) {
System.out.println("Error.");
}
'字符串myArray的[] = str.split(“:”);'在java [String](http://docs.oracle.com/javase/6/docs/api/java/lang/String.html)类中有许多方法这些类型的东西。 – 2012-01-11 14:46:40
你的文件只包含一行......所以readline在读取该行时比离开循环,因为第二次in.readline返回null – Hons 2012-01-11 14:47:14
你对BufferedReader的使用看起来是正确的。你没有看到“hello.txt”的逐行输出吗? – dasblinkenlight 2012-01-11 14:47:57