我正在尝试从如下所示的文本文件中读取字符串:
# hello my name is captain
1111 $3340 4
1211 $9182 5
1211 $9192 9if(!line.startsWith("#")) {
System.out.println(line);
}这会打印出除#之外的所有内容
hello my name is captain
1111 $3340 4
1211 $9182 5
1211 $9192 9我找不到任何使用!符号的例子,也不知道我做错了什么。
发布于 2012-11-18 19:46:49
尝尝这个。代码中的错误在注释前包含一个空格。因此,请检查修剪它。
BufferedReader reader = new BufferedReader(new FileReader(new File("path-to-file")));
String line;
while ((line = reader.readLine()) != null){
if (!line.trim().startsWith("#")){
System.out.println(line);
}
}https://stackoverflow.com/questions/13439749
复制相似问题