strange characters at the end of directory in android
-
18-03-2021 - |
Question
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?
Solution
File can't store or save with some special character as below.
/\:?*"<>|