String hi = System.getProperty("user.dir");
String noes = "%USERPROFILE%\\Start Menu\\Programs\\Startup\\";
String sex = "/bin/s";
Path FROM = Paths.get(hi, sex);
Path TO = Paths.get(noes, "s");
System.out.println(TO);
try {
Files.copy(FROM, TO);
} catch (IOException e) {
e.printStackTrace();
}
調試:NoSuchFileException即使有?爪哇(試圖添加文件的啓動窗口)
%USERPROFILE%\Start Menu\Programs\Startup\s
java.nio.file.NoSuchFileException: C:\Users\Sand N\workspace\miner\bin\s -> %USERPROFILE%\Start Menu\Programs\Startup\s
at sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:79)
at sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:97)
at sun.nio.fs.WindowsFileCopy.copy(WindowsFileCopy.java:205)
at sun.nio.fs.WindowsFileSystemProvider.copy(WindowsFileSystemProvider.java:278)
at java.nio.file.Files.copy(Files.java:1225)
at miner.mine.main(mine.java:18)
將不勝感激所有幫助,感謝這麼多stackoverflower的!
我很困惑,說實話,不是這樣,不幸的是有什麼不對。
我知道的一個事實的啓動文件夾路徑是正確的,但我不知道是否喜歡Java的某些鍵如%,/等
我的猜測是環境屬性'%USERPROFILE%'沒有被解析。改用'System.getProperty(「user.home」)'。 –