码迷,mamicode.com
首页 > 其他好文 > 详细

CreateFileDemo

时间:2015-05-26 20:51:25      阅读:135      评论:0      收藏:0      [点我收藏+]

标签:

import java.io.File;
import java.io.IOException;

public class CreateFileDemo {
	public static void main(String[] args) {
		try {
			File file = new File("D:\\newfile.txt");
			/*
			 * If file gets created then the createNewFile() method would return
			 * true or if the file is already present it would return false
			 */
			boolean fvar = file.createNewFile();
			if (fvar) {
				System.out.println("File has been created successfully");
			} else {
				System.out.println("File already present at the specified location");
			}
		} catch (IOException e) {
			System.out.println("Exception Occurred:");
			e.printStackTrace();
		}
	}
}

  

http://beginnersbook.com/2014/01/how-to-create-a-file-in-java/

 

CreateFileDemo

标签:

原文地址:http://www.cnblogs.com/lnas01/p/4531546.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!