如何 read/write 一个文件到网络附加存储 Java Android

How to read/write a files to a network attached storage Java Android

我目前正在 Android 工作室开发一个应用程序,用于将测试文件写入和读取到网络附加存储。然而,事实证明很难找到 write 方法。我一直在尝试使用 jcifs。网络附加存储需要使用用户名和密码登录。对于 jcifs,我一直在尝试使用 NtlmPasswordAuthentication 但是我似乎可以正确地实现它,因为每次我尝试 运行 这种方法时,应用程序都会强制关闭。

请有人展示如何写入和读取需要登录名和密码的网络附加存储。

感谢大家的帮助!

我注意到我把这个 post 放上去了,我确实有一个解决方案可以让我从网络附加存储中读取文本文件。 希望这对您有所帮助!

private String ReadFilefromNAS(String s, String Username, String Password) {
    //s is the filename path on the NAS
    String file = "";
    SmbFile dir;
    NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication(null, Username, Password);
        dir = new SmbFile(FilePath + s, auth);
        //If your not using auth use the below
        //dir = new SmbFile(FilePath + s);
        InputStream in = dir.getInputStream();
        BufferedReader q= new BufferedReader(new InputStreamReader(in));
        String line;
        int i = 0;
        while ((line = q.readLine()) != null) {
            if(i==0){
                file+=line;
            }else {
                file += "\n" + line;
            }
            i+=1;
        }
    }catch(Exception e){
        Log.e("ERROR",e.toString());
    }
    return file;
}