以下实例演示了使用 file 类的 file.createtempfile() 方法在指定目录中创建文件:
/*
author by w3cschool.cc
main.java
*/import java.io.file;public class main {
public static void main(string[] args)
throws exception {
file file = null;
file dir = new file("c:/");
file = file.createtempfile ("javatemp", ".javatemp", dir);
system.out.println(file.getpath());
}}
以上代码运行输出结果为:
c:\javatemp37056.javatemp
以上就是java 实例 - 在指定目录中创建文件的内容。