当前位置: 代码迷 >> Java相关 >> 请问这个这个程序建一个文件,并向文件中写入数据有问题吗?
  详细解决方案

请问这个这个程序建一个文件,并向文件中写入数据有问题吗?

热度:109   发布时间:2007-12-16 10:36:26.0
请问这个这个程序建一个文件,并向文件中写入数据有问题吗?
package javaDaZuoYeFuZhu;
import java.io.*;
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!");
        }
                    
    }

}


}
搜索更多相关的解决方案: 文件  数据  

----------------解决方案--------------------------------------------------------
myPrintWriter=new PrintWriter(myFileWriter);
myPrintWriter=new PrintWriter(strContent);
myPrintWriter.println(strContent);

你前两句是搞什么?
----------------解决方案--------------------------------------------------------
  相关解决方案