这就是我所发现的,但是在这段代码中,它会读取你输入的内容,我不希望这样
我正在做一个名为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");
}
Run Code Online (Sandbox Code Playgroud) java ×1