android目录末尾有奇怪的字符

发布于 2024-12-21 16:00:28 字数 638 浏览 4 评论 0原文

我在 Android 中创建目录时遇到问题。我使用此代码创建一个目录(如果不存在),然后在其下创建一个文件。

dir=new File(Constants.TASK_DIRECTORY);
if(!dir.exists())
dir.mkdirs();
file=new File(dir, FILENAME);   
file.createNewFile();

有时它工作正常,但有时当我从 adb shell 检查文件夹时,我会看到以 3 个或更多 "|" 字符结尾的目录。我的目录名称格式是 “Abc_123-10.10.2000”。我有时看到的是完全相同的,但有时是 "Abc_123-10.10.2000|||" 。我需要借助名称格式来访问目录下的文件,但这种情况使其变得困难,任何帮助将不胜感激。

我在此代码应用程序中设置 TASK 目录

Constants.TASK_DIRECTORY=getFilesDir()+"/"+app.getUserName()+"-"+dt;

是我的应用程序对象

编辑:解决了此问题,这是因为 TASK_DIRECTORY 未正确设置并包含“|”人物。但这怎么可能呢?

I have an issue with directory creation in Android. I use this code to create a directory if doesn't exist and then create a file under it.

dir=new File(Constants.TASK_DIRECTORY);
if(!dir.exists())
dir.mkdirs();
file=new File(dir, FILENAME);   
file.createNewFile();

Sometimes it works fine, but sometimes when I check the folder from adb shell I see directories ending with 3 or more "|" characters. My directory name format is
"Abc_123-10.10.2000 ". What I see sometimes is exactly the same, but sometimes "Abc_123-10.10.2000|||" . I need to access the files under directories with the help of their name format but this situation makes it hard, any help would be appreciated.

I set TASK directory in this code

Constants.TASK_DIRECTORY=getFilesDir()+"/"+app.getUserName()+"-"+dt;

app is my application object

Edit: Solved this problem, it was because TASK_DIRECTORY was not properly set and contains "|" characters. But how can this be possible?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

只怪假的太真实 2024-12-28 16:00:28

文件无法存储或保存某些特殊字符,如下所示。

      /\:?*"<>|  

File can't store or save with some special character as below.

      /\:?*"<>|  
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文