我想用java.But創建一個臨時文件,當我運行我的代碼時它顯示以下錯誤。我無法創建臨時文件
number.java:7: cannot find symbol
symbol : class Path
location: class number
Path tempFile = Files.createTempFile(null, ".txt");
^
number.java:7: cannot find symbol
symbol : method createTempFile(<nulltype>,java.lang.String)
location: class Files
Path tempFile = Files.createTempFile(null, ".txt");
^
2 errors
和這裏的代碼 ,當我進口的java.io.File;。然後它顯示錯誤包不存在
import java.io.*;
public class number{
public static void main(String args[])
{try {
Path tempFile = Files.createTempFile(null, ".txt");
System.out.format("The temporary file" +
" has been created: %s%n", tempFile);
} catch (IOException x) {
System.err.format("IOException: %s%n", x);
}
}}
請參閱本:http://stackoverflow.com/questions/617414/create-a-temporary-directory-in-java其中包 –
'Files'來?我猜應該是'File'。 – AmitG
java.nio.file.Files – Ankit