gpt4 book ai didi

android - 如何仅浏览我的应用程序中的文本文件

转载 作者:行者123 更新时间:2023-11-29 01:43:57 32 4
gpt4 key购买 nike

我已经构建了一个应用程序,我应该只浏览设备中的 txt 文件并阅读它。但我没有得到有效的解决方案。例如,如果我们使用 whatsapp,你可以浏览不同的不同标题下的文件,比如在视频下你只能浏览视频,在图库下你只能浏览图片。但是如果只有文本文件怎么办?有什么办法吗?请建议。

最佳答案

try this.

//for example your folder present in sdcard/cts.
File f = new File(Environment.getExternalStorageDirectory().getAbsolutePath()+ "/cts");
for (File wavfile : f.listFiles(new FileExtensionFilter()))
{
String str = wavfile.getName().toString();
}

//create a class and the filter based on your need file extension
class FileExtensionFilter implements FilenameFilter {
public boolean accept(File dir, String name) {
return (name.endsWith(".txt") || name.endsWith(".TXT") );
}
}

thank you.

关于android - 如何仅浏览我的应用程序中的文本文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22652100/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com