【发布时间】:2020-05-08 06:48:09
【问题描述】:
嘿,我正在做的这个练习需要一些帮助。我必须打开一个名为 hello.txt 的文件,然后存储消息“Hello World!”在文件中。然后我必须关闭文件并打开它,并将消息读入字符串变量以打印它。到目前为止,我在下面有这段代码。您对我如何成功编译此代码有什么建议吗?
package ProgrammingExercise11;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.Scanner;
public class Input {
public static void main(String[] args) throws FileNotFoundException
{
Scanner in = new Scanner(System.in);
File inputFile = new File(hello.txt);
Scanner in = new Scanner(inputFile);
PrintWriter out = new PrintWriter(hello.txt);
out.println("Hello, World!");
String line = in.nextLine();
in.close();
out.close();
}
}
【问题讨论】:
-
如果您的代码无法编译,请告诉我们您的编译器给您的错误信息。
标签: java input netbeans output