小编Nik*_*l V的帖子

如何从命令提示符获取输出并使用语言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");
}
Run Code Online (Sandbox Code Playgroud)

java

0
推荐指数
1
解决办法
3328
查看次数

标签 统计

java ×1