用FileWriter将内容写入文本
import java.io.*;
public class FileWriterTest
{
public static void main(String[] args)
{
FileWriterTest t = new FileWriterTest();
t.WriteMyFile();
}
void WriteMyFile()
{
try
{
FileWriter fw = new FileWriter("mydata.txt");
PrintWriter out =new PrintWriter(fw);
out.print("Hello,World!");
out.close();
fw.close();
}
catch(IOException e)
{
System.out.println("OH,got an IOException error!");
e.printStackTrace();
}
}
}