[英]How to read/write a files to a network attached storage Java Android
我目前正在Android Studio中开发一个应用程序,以将测试文件写入和读取到网络附加存储。 但是,事实证明很难找到写入方法。 我一直在尝试使用jcifs。 网络连接的存储需要使用用户名和密码登录。 使用jcifs,我一直在尝试使用NtlmPasswordAuthentication,但是我似乎可以正确实现它,因为每次我尝试运行此方法时,应用程序都会强制关闭。
请有人告诉我们如何写入和读取需要登录名和密码的网络连接存储。
感谢大家的帮助!
我注意到我张贴了这篇文章,并且确实有一种解决方案,允许我从Network Attach Storage中读取文本文件。 希望这可以帮助!
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;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.