【发布时间】:2015-04-27 06:18:03
【问题描述】:
public void a(){
File dir = new File("/mnt/sdcard/files");
String[] children = dir.list();
for (String s : children){
if(s.contains("cache")){
System.out.println(s);
// Means Found
Toast.makeText(getApplicationContext(), "Found", Toast.LENGTH_SHORT).show();
}
}
// Means No Found
Toast.makeText(getApplicationContext(), "Not Found", Toast.LENGTH_SHORT).show();
return;
}
我真正想要的就是这样的
我在“/mnt/sdcard/files”中有很多文件
我想搜索包含一些已知名称的文件,让我们使用“缓存” 我可以这样列出
System.out.println(s);
输出将是
- cache.bin
- newcachete.txt
- 文件缓存
类似的东西
但我真正想要的是这个函数返回包含单词“缓存”的文件的全名,并在另一个函数的不同字符串中为其赋值
例如,如果这个函数返回 String = newcachete.txt,这样我就可以在另一个函数中分配它的值
public void newfunction(){
String new = a();
// this string will contain newcachete.txt
}
但由于可能有很多文件包含此名称,所以我想返回我可以在新函数中分配的所有文件名
例如
public void newfunction(){
String new = a();
// this string will contain newcachete.txt
// and like that i want it to conatain every different name
/*
String a = cachenew.bin;
String b = filecachete.txt;
*/
}
在不同的功能 有什么办法吗?
感谢您的回答,感谢您给我时间:)
我正在寻找更好的答案
【问题讨论】:
-
你可以将它存储在数组中。
-
你能写一些代码帮助吗?
-
什么是cachenew.bin?
-
这是我随机取的文件名:)
-
我已按要求进行了编辑,现在它会清理并让您更好地理解 :)