现在的位置: 首页 > 综合 > 正文

java创建文件夹或文件

2014年07月01日 ⁄ 综合 ⁄ 共 313字 ⁄ 字号 评论关闭
public static void createFile() throws IOException{
			String path0 = "E:/evan";
			String path1 = "E:/evan/zl.txt";  //创建文件时,这个文件夹必须存在,否则会报错。也就是“E:/evan”这个文件夹必须存在
			File file = new File(path0);
			//创建文件夹
			if(!file.exists()){
				file.mkdir();
			}
			//创建文件
			file = new File(path1);
			if(!file.exists()){
				file.createNewFile();
			}
			
			
		}

我用这个主要是图片,文件上传的时候,如果服务器不存在此文件夹,那么会自动创建。

抱歉!评论已关闭.