编程如何打开smb共享文件? 相信多数人都知道用ES文件管理器可以打开网络邻居上的其它机器的共享资源,还可以直接调用相关应用打开文件,看其属性,是类似:smb://192.168.1.123/pub/file.txt这样的路径。现在遇到一个问题:在自己编的程序中,怎么打开这样的共享文件呢?试了FileInputStream和getContentResolver().openInputStream(Uri.parse(url))都不识别上述文件路径。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 使用jcifs 开源库,贴段代码 try { //指定服务器共享文件的路径,访问账号密码 SmbFile smbFile = new SmbFile("smb://jlansrv:[email protected]:1445/JLAN/test.lrc"); int length = smbFile.getContentLength(); System.out.print("contentLength = " + length); byte buffer[] = new byte[length]; try { SmbFileInputStream in = new SmbFileInputStream(smbFile);//读取文件数据流,具体操作跟普通的File类似 while(in.read(buffer) != -1) { System.out.println(new String(buffer)); System.out.println("buffer.length = " + buffer.length); } } catch (IOException e) { e.printStackTrace(); } } catch (MalformedURLException e) { e.printStackTrace(); } 建议研究一下smb和jcifs。 关于android视频采集的问题,急求解 神奇的return语句 竟然一个方法中执行了两个return 不解 请教下 Eclipse的常用快捷键 如何在模拟器system/app中安装自己的apk Android SMSPopup源码问题求助。 execSQL和insert,用哪个好点? android系统什么软件打开.chm 格式文件带树状菜单的 webview简单问题 android射频参数 使用AsyncTask遇到的一个奇怪现象 Android getSharedPreferences 问题 关于wap,是不是有很多bug啊
try {
//指定服务器共享文件的路径,访问账号密码
SmbFile smbFile = new SmbFile("smb://jlansrv:[email protected]:1445/JLAN/test.lrc");
int length = smbFile.getContentLength();
System.out.print("contentLength = " + length);
byte buffer[] = new byte[length];
try {
SmbFileInputStream in = new SmbFileInputStream(smbFile);//读取文件数据流,具体操作跟普通的File类似
while(in.read(buffer) != -1) {
System.out.println(new String(buffer));
System.out.println("buffer.length = " + buffer.length);
}
} catch (IOException e) {
e.printStackTrace();
}
} catch (MalformedURLException e) {
e.printStackTrace();
}