I am looking for a maybe better solution to get the path of a file inside a folder.
For example:
I have the absolute path: "/storage/emulated/0/Mobile Pauker++/Lessons/Berge/Hoechste-Berge.pau.gz"
And I want to get: "Lessons/Berge/Hoechste-Berge.pau.gz"
My current solution is:
filepath.substring(filepath.indexOf("Mobile Pauker++")+15)
But I don't think that this is a good solution.
Please try this val path = File(Environment.getExternalStorageDirectory().toString() + File.separator + "Lessons/Berge/Hoechste-Berge.pau.gz")
I think I found a good solution:
filepath.split("${Environment.getExternalStorageDirectory()}${Constants.DEFAULT_APP_FILE_DIRECTORY}")[1]
I give the .split() method the path of my "root folder" and take the second part.
Related
I want to use the renameTo method to copy a file into another folder but I don't know the path. I want to put a file into the "DCIM" folder in the internal Storage.
oldFile.renameTo(new File("That is the path name I need" + "/myData.txt"));
Thank you very much!!!
File dcim=Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM);
oldFile.renameTo(new File(dcim, "myData.txt"));
As i need to load a file from SDCard when i am using Environment.getExternalStorageDirectory() or Environment.getExternalStorageDirectory().getAbsolutePath() but it is not working, well it works great with the "file:///sdcard/Avalon/assets/www/filename.html". I don't know what is happening with my path
cwv.loadUrl(Environment.getExternalStorageDirectory().getAbsolutePath()+"/Avalon/assets/www/filename.html", map);
I want make my path generic that's why i need to work it with any generic term...
Great it works... Actually i forgot to add "file://"
So actual path should be
cwv.loadUrl("file://"+Environment.getExternalStorageDirectory().getAbsolutePath()+"/Avalon/assets/www/filename.html", map);
This is my mistake thanks
Hope the subject line makes it clear.
I want to get hold of the file path of the xml file which i store under the res/xml folder.
I'm aware of the InputStream approach by directly reading using the snippet.
... getResources().getXml(R.raw.testxml);
but my requirement is to just get the path of the stored file for the moment.
Any help appreciated
VATSAG
try as to get full path of file stored in res/raw folder
String fullpath = "android.resource://" +
YOUR_FULL_PACKAGE_NAME +
"/"+R.raw.testxml;
I've a problem with reading a XML file in my APP. I've tried multiple options but I'm getting error that read acces is false. I'm sure I'm using the correct path.
XML = new File(XML, "file.xml");
Log.i("XML", "Read access:" + XML.canRead());
This does return a false, I only need to read not to write (at least, not yet..).
System.getProperty(XML.getPath())
Returns null
I think there is a problem with the SD card (see other issue). But in my app I can open diffent folders except the XML file in the last folder.
I've added the correct permission to the manifest file.
Any help is very much appreciated. Thank you.
Edit:
File path:
File f = new File(Environment.getExternalStorageDirectory().toString()
+ File.separator
+ "external_sd"
+ File.separator
+ "app"
+ File.separator
+ "Games"
+ File.separator
+ "Version_1"
);
I've no problem with opening the folders. In my last folder there wil be a xml which can't be opened.
I'm using part of the path in other parts of the APP and there it works..
Also the code XML.exists() returns false...
Was related to to other issue, that one also solved this issue
all thanks for the help..
I want to read text file, that was written by other my app. It's saved ad "Android/data/MyPackageName/files/"
I use this code:
File file = new File("//Android//data//MyPackageName//files//", "filename.txt");
FileInputStream is = new FileInputStream(file);
but i get exception "no such file or directory"
I am sure that solution is pretty simple, but i can't find it yet.
Thank you for your help!
I don't think it is right to use the double backslash "//", one is enough. Also, the path should be "/mnt/sdcard/Android/data....". I am not sure the "/mnt/sdcard" is applicable on every device, so my suggestion is to use Environment.getExternalStorageDirectory to get the root dir on sd card.