文件创建
package CreateFILES; import java.io.File; import java.io.IOException; public class IO { public static void main(String[] args) { // TODO Auto-generated method stub // created01(); // created02(); created03(); } public static void created01() { String filePath = "d:\\news1.txt" ; File file = new File(filePath); //只有执行了creatNewFile才会真正在磁盘中创建文件 try { file.createNewFile(); System.out.println("SUCCESS"); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public static void created02() { File parentFile = new File("D:\\"); String filename = "news2.txt"; File file = new File(parentFile,filename); try { file.createNewFile(); System.out.println("SUCCESS"); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public static void created03() { String parentPath = new String("D:\\"); String fileName = new String("new3.txt"); File file = new File(parentPath, fileName); try { file.createNewFile(); System.out.println("SUCCESS"); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
标签:String,文件创建,File,JAVAIO,file,catch,new,public From: https://www.cnblogs.com/konataxzy/p/16738058.html