簡體   English   中英

NoSuchFileException即使有? Java(嘗試在啟動窗口上添加文件)

[英]NoSuchFileException even though there is? Java (trying to add file on startup windows)

        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();
        }

調試:

%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是否喜歡某些鍵,例如%,/等。

與其直接訪問Windows環境路徑, System.getenv("USERPROFILE")嘗試使用System.getenv("USERPROFILE")獲取用戶配置文件的目錄,然后構建路徑。

 String noes =  System.getenv("USERPROFILE") + "\\Start Menu\\Programs\\Startup\\";

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM