這就是我所發現的,但是在這段代碼中它讀取了放入的內容的行,並且我不想要那如何從命令提示符處取出輸出並使用語言創建文本文件Java
我正在做一個名爲Knight's Tour的程序,並且我在命令提示符下獲取輸出。我想要做的就是從命令提示符中讀取行並將其存儲爲名爲knight.txt的輸出文件。誰能幫我嗎。謝謝。
try
{
//create a buffered reader that connects to the console, we use it so we can read lines
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
//read a line from the console
String lineFromInput = in.readLine();
//create an print writer for writing to a file
PrintWriter out = new PrintWriter(new FileWriter("output.txt"));
//output to the file a line
out.println(lineFromInput);
//close the file (VERY IMPORTANT!)
out.close();
}
catch(IOException e)
{
System.out.println("Error during reading/writing");
}
沒有太多的點張貼代碼,不做你想做的,是嗎? – EJP