【发布时间】:2014-12-08 19:27:57
【问题描述】:
我被要求将我当前的程序保存到一个文件中,以便以后即使程序结束也可以继续。但是我是java新手,所以如果有人能帮我解决这个问题,我将不胜感激:)这是我设法完成的代码,但它只是创建了一个空文件,我该如何解决这个问题?
以下不是整个程序编码,我只是复制了相关的代码。
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.io.FileWriter;
public static void main (String[] param) throws FileNotFoundException
{
try
{
fileinputoutput ();
}
catch (FileNotFoundException e)
{
System.exit(0);
}
} // END main
public static void fileinputoutput() throws FileNotFoundException
{
File input = new File("input.txt");
File output = new File("loveletter.txt");
PrintWriter outputFile = new PrintWriter(output);
Scanner check = new Scanner(System.in);
String filename = check.nextLine();
File inputfile = new File(filename);
Scanner newfile = new Scanner(inputfile);
newfile.close();
while(newfile.hasNext())
{
String write = newfile.nextLine();
System.out.println(write);
}
outputFile.close();
}
【问题讨论】:
-
我不明白这个问题。请明确明确。
-
你知道你只输出到
System.out吗? -
@flashdrive2049 发布你的答案,这样我就可以投票给你了
-
我自己也很困惑,我正在做一个练习,要求我将我的程序保存到一个文件中,以便以后即使程序结束也可以继续。我想使用文件/输出。我不知道该怎么做:/ @Michal Wilkowski
-
我正在寻找答案。