1. 程式人生 > >如何用java建立一個檔案

如何用java建立一個檔案

      public void createFile(){
        
        String path= "G:\\yuchao\\測試";//所建立檔案的路徑
        
        File f = new File(path);
        
        if(!f.exists()){
            
            f.mkdirs();//建立目錄
        }
        
        String fileName = "abc.txt";//檔名及型別
        
        File file = new File(path, fileName);
        
        if(!file.exists()){
            
            try {
                file.createNewFile();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            
        }
        
    }