⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 文件创建删除类.txt

📁 一些自己平时积累的小知识点, java 的 javaee 的
💻 TXT
字号:

 
import  java.io.BufferedWriter;  
import  java.io.File;  
import  java.io.FileWriter;  
import  java.io.IOException;  
public  class    CreateNewFile  {  
           /**  
           *  删除文件  
           */  
           public  void  deleteFile(String  path){  
                       File  f=new  File(path);    //path:E:/tomcat/...  
                       try{  
                                     f.delete();  
                       }catch(Exception  e){}  
           }  
 
           /**  
           *创建文件  
           */  
           public  boolean  createFile(String  _path,  String  _fileName)    
                                         throws  IOException  {  
                       boolean  success  =  false;  
                       String  fileName  =  _fileName;  
                       String  filePath  =  _path;  
                       try  {  
                                   File  file  =  new  File(filePath);  
                                   if  (!file.isDirectory())  {  
                                               file.mkdirs();  
                                   }  
                                   File  f  =  new  File(filePath  +  File.separator    
                                                                       +  fileName  +  ".txt");  
                                   success  =  f.createNewFile();  
 
                       }  catch  (IOException  e)  {  
                                   e.printStackTrace();  
                       }  
                       return  success;  
 
           }  
 
           /**  
           *  向文件中写入数据  
           */  
           public  void  writeFile(String  _path,  String  _fileName,  
                                                     String  insertString,boolean  isLast)    
                                                     throws  IOException  {  
 
                       try  {  
                                   BufferedWriter  out  =  new  BufferedWriter(new  FileWriter(_path  +  File.separator  +  _fileName  +  ".txt"));  
                                   out.write(insertString);  
                                   if(!isLast)  out.newLine();  
                                   out.flush();  
                                   out.close();  
                       }  catch  (IOException  e)  {  
                                   e.printStackTrace();  
                       }  
 
           }  
 
}  
 
 
 
---------------------------------------------------------------  
 
File  file  =  new  File("d:\asd");  
file.mkdir();或者file.mkdirs()  

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -