好的,所以我正在尝试创建一个java程序,它将读取一个txt文件并将每一行转换为String。例如,txt文件可能类似于
This should be a string
This should be another string
And another string
目前我的代码只允许我将txt文件转换为一个字符串。
String Content = new Scanner(new File ("CONTENTS.txt")).useDelimeter(",").next();
System.out.println(Content);
答案 0 :(得分:2)
Scanner scanner = new Scanner(new FileInputStream(fileName));
while(scanner.hasNextLine()) {
String line = scanner.nextLine();
// process line here..
}