package prgms;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
class new_experi {
public static void main(String[] args) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter out = new BufferedWriter(new FileWriter("C://Users//sihi//Desktop//output.txt"));
try
{
String inputLine = null;
do {
inputLine = in.readLine();
out.write(inputLine);
out.newLine();
} while (!inputLine.equalsIgnoreCase("eof"));
System.out.print("Write Successful");
} catch (IOException e1) {
System.out.println("Error during reading/writing");
} finally {
out.close();
in.close();
}
}
}
我正在获得输出但是最后一行,即"写成功"未复制到文件中。
答案 0 :(得分:0)
答案 1 :(得分:0)
System.out.print("")将输出到控制台,你应该使用out.write("")代替。