Java创建文件

	public void createFile() {


		// path表示你所创建文件的路径
		String path = "d:/tr/rt";
		File f = new File(path);
		if (!f.exists()) {
			f.mkdirs();
		}
		// fileName表示你创建的文件名;为txt类型;
		String fileName = "test.txt";
		File file = new File(f, fileName);
		if (!file.exists()) {
			try {
				file.createNewFile();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}


	}
	// 现在你可以在d:/tr/rt 目录下找到test.txt文件


原文地址:https://www.cnblogs.com/pekkle/p/6568682.html