[英]BufferedWriter newLine method not found
我試圖獲得一個BufferedWriter來打印幾個字符串,每個字符串在文本文件的不同行上。 我正在嘗試使用out.newLine()
為下一個字符串設置新行,但是我收到一條cannot find symbol - method newLine()
的錯誤消息cannot find symbol - method newLine()
這是我嘗試使用的代碼:
Writer out = null;
try {
out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(start+"2"+dest+".txt"), "utf-8")); // create output file from start names
out.write(outputOne);//Write Line 1
out.newLine();
out.write(outputTwo); //Write Line 2
out.newLine();
out.write(outputThree); //Write Line 3
out.newLine();
out.write(outputFour); //Write Line 4
out.close();
} catch (IOException ex) { //Handle Errors
System.err.println("Error in BufferedWriter, IOException");
} finally {
try {out.close();}
catch(Exception ex) {}
}
使用BufferedWriter
類型聲明變量。 Writer
沒有newLine()
方法。
BufferedWriter out;
方法在編譯時根據調用它們的變量(或表達式)的聲明/靜態類型進行解析。
或者,強制轉換變量
((BufferedWriter)out).write(outputFour);
但這很長。
考慮使用try-with-resources 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.