`
zjx2388
  • 浏览: 1305674 次
  • 性别: Icon_minigender_2
  • 来自: 北京
社区版块
存档分类
最新评论

创建文件

    博客分类:
  • J2SE
F# 
阅读更多
import java.io.File;

public class CreateFile {

	public static void main(String args[]) {
		try {

			/*查找目录,如果不存在,就创建*/
			File dirFile = new File("F:/fileroot");
			if (!dirFile.exists()) {
				if (!dirFile.mkdir()) {
//					throw new Exception("目录不存在,创建失败!");
					//创建这个目录
					dirFile.createNewFile();
				}

			}
			/**//*查找文件,如果不存在,就创建*/
			File file = new File("F:\\fileroot\\newFile.txt");
			if (!file.exists())
				if (!file.createNewFile()) {
//					throw new Exception("文件不存在,创建失败!");
					//创建这个文件
					file.createNewFile();
				}
		} catch (Exception e) {
			System.out.println(e.getMessage());
		}
	}
}

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics