[英]How to get multiple Strings from .txt file
好的,所以我正在嘗試創建一個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);
請閱讀適用於Scanner的javadoc :
Scanner scanner = new Scanner(new FileInputStream(fileName));
while(scanner.hasNextLine()) {
String line = scanner.nextLine();
// process line here..
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.