【发布时间】:2019-03-16 02:07:56
【问题描述】:
这是我的代码:
import java.io.File;
import java.io.BufferedReader;
import java.io.FileReader;
public class SymbolBalance{
public static void main(String[] args) throws Exception{
File givenFile = null;
String words = null;
if(args.length > 0){
givenFile = new File(args[0]);
} else{
System.out.println("Error! No file name was given!");
}
BufferedReader scan = new BufferedReader(new FileReader(givenFile));
while(words = scan.readLine() != null){
System.out.println(words);
}
scan.close();
}
}
这是我的错误:
codio@titanic-avenue:~/workspace$ javac SymbolBalance.java
SymbolBalance.java:21: error: incompatible types: boolean cannot
be converted to String
while(words = scan.readLine() != null){
^
SymbolBalance.java:21: error: incompatible types: String cannot
be converted to boolean
while(words = scan.readLine() != null){
我正在尝试从命令行获取一个文件,对其进行扫描,然后在终端中逐行打印出文件中的内容。我知道 bufferedreader 不能直接与 Strings 一起使用,这是我使用 FileReader 的原因,但我仍然得到一个 boolean to string 和 string to boolean 错误。有人可以指出我找到此错误的正确方向吗?
【问题讨论】:
-
在此处以文本形式发布您的代码
-
知道了,马上编辑。
标签: java bufferedreader filereader