请问这个这个程序建一个文件,并向文件中写入数据有问题吗?
package javaDaZuoYeFuZhu;import *;
public class WriteImfomationToFile {
public static void main(String args[])throws Exception{
String filePath="f:\\TheInfomationOfTheVistors\\login.txt";
//新建指定路径的文件夹
File myFile;
FileWriter myFileWriter;
PrintWriter myPrintWriter;
myFile=new File(filePath);
if(!myFile.exists()){
try{
myFile.createNewFile();
}catch(IOException e){
System.out.println("Creat new file failed!");
}
String strContent="Test ...OK!";
try{
myFileWriter=new FileWriter(myFile);
myPrintWriter=new PrintWriter(myFileWriter);
myPrintWriter=new PrintWriter(strContent);
myPrintWriter.println(strContent);
myFileWriter.close();
}catch(IOException e){
System.out.println("Creat new file writer or printer failed!");
}
}
}
}