gpt4 book ai didi

android - 脱掉 .txt 上的字符串?

转载 作者:行者123 更新时间:2023-11-29 21:40:57 24 4
gpt4 key购买 nike

我的应用程序有一个 ListActivity,它显示特定目录中的所有 .txt 文件。这是获取文件名的代码:

 List<String> textFiles(String directory) {
List<String> textFiles = new ArrayList<String>();
File dir = new File(directory);
for (File file : dir.listFiles()) {
if (file.getName().endsWith((".txt"))) {
textFiles.add(file.getName());
}
}
return textFiles;
}

问题是所有返回的文件名都以 .txt 结尾。我怎样才能让结局被切断?谢谢!

最佳答案

您可以简单地使用String.replace 方法

例如

String newName = file.getName().replace(".txt","");

关于android - 脱掉 .txt 上的字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17126603/

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