CreateFileDemo

时间:2015-05-26 20:48:59   收藏:0   阅读:167
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/

 

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

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!