【发布时间】:2019-04-26 01:02:38
【问题描述】:
我已连接到地址为 192.168.1.254 的服务器,在浏览器中输入此地址时,它会显示可用文件夹列表 我想在我的 android 应用程序中显示文件夹的名称我尝试了以下代码但没有运气。
try {
SmbFile test = new SmbFile("smb://192.168.1.254");
SmbFile[] files = test.listFiles();
if (files != null)
for (SmbFile s : files) {
Log.d("debug", s.getName());
}
} catch (SmbException e) {
Log.d("debug", "ERROR");
} catch (Exception e) {
Log.d("debug", "ERROR");
}
我找到here 我也试过了
File f = new File("//192.168.1.254");
//also tried with File f = new File("http//192.168.1.254");
File[] files = f.listFiles(new FilenameFilter() {
public boolean accept(File dir, String name) {
// Specify the extentions of files to be included.
return name.endsWith(".bmp") || name.endsWith(".gif");
}
});
// get names of the files
String[] fileNamesArray = null;
for (int indx = 0; indx < files.length(); indx++) {
Log.d("name",files[indx].getName());
}
return fileNamesArray;
【问题讨论】:
标签: android directory subdirectory file-access