簡體   English   中英

無法寫入Java中的遠程文件系統

[英]Cannot write to a remote file system in java

我正在使用Play! 框架。 我想訪問通過LAN連接的遠程文件(讀和寫)。 在Java中首次訪問以讀取文件時。 我無法讀取該文件。 如果我一次(成功)將URL加載到瀏覽器中,那么我也可以用Java讀取文件。 (我正在使用HttpURLConnection進行讀取)現在我想寫入無法寫入的文件。 沒有錯誤或例外。 但是內容未寫入文件。 我已授予777游戲許可! 應用。 可能是什么問題。 我該如何解決。

編輯:

要更新文件,我已編寫此代碼

public void createFileInPath(String filePath, Object contents)
   {
        try{

        Writer output = null;
        String text = contents.toString();
        File file = new File(filePath);
        output = new BufferedWriter(new FileWriter(file));
        output.write(text);
        output.close();

        }catch (Exception e){
        System.err.println("Error While Creating File in FileManager.java: " + e);
        }
   }

嘗試使用java.io. *類。 如果已將其安裝在系統(linux)或已映射(windows)上,則無需特別對待。

您需要做的就是傳遞正確的路徑並像本地文件一樣進行操作。

讀取文件:

    BufferedReader in = new BufferedReader(new FileReader("my file path"));
    String line = null;
    while ((line = in.readLine()) != null) {
        System.out.println(line);
    }
    in.close();
    // To write into a file
    PrintWriter out = new PrintWriter(new FileWriter("my file path"));
    out.println("some content");
    out.flush(); // required to flush the content to filesystem
    out.close();

暫無
暫無

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

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