+ 2

Java - How to create a file on phone using JvDroid?

In Java tutorial, we are taught to work with files on computer. How to work with files on our phone?đŸ€” I already used JvDroid I have a file named kira.txt in my internal storage. File f= new File("kira.txt") System.out.print( f.exists() ); Why the output is false?

30th May 2021, 7:23 AM
Muhd Khairul Amirin
Muhd Khairul Amirin - avatar
12 Answers
+ 3
that's an example of my internal storage ;) in fact internal storage is usually named 'sdcard' (think of it as an unmovable sdcard) android use linux/unix file system... external sd are mounted to miscelanous directory names under /sdcard/ (could differ related to phone manufacterer...) and could be mounted at different places at same time (different valid path to access same sd/directories) the simpler and safest to get the path of your file would be to use a file explorator wich could give it to you (almost all decents: I currently use an old version of ES File Explorer, and Total Commander on an old phone)... on my old phone the paths look like: /storage/sdCard0/download/file.txt for internal storage and /storage/extSdCard/folder/fike.txt for external storage
30th May 2021, 9:02 AM
visph
visph - avatar
+ 2
visph I use JvDroid on my phone
30th May 2021, 8:07 AM
Muhd Khairul Amirin
Muhd Khairul Amirin - avatar
+ 2
I don't know: maybe it's either a problem of you're not executing the code in the directory containing the file (working directory: may be different of those where the script/executable reside), or a problem related to file permissions: android tends to be very strict about that ;P
30th May 2021, 8:13 AM
visph
visph - avatar
+ 2
something like: /sdcard/Download/file.txt absolute path must start with a slash (root is /) without the starting slash, the path will be relative to the current working directory (folder)
30th May 2021, 8:38 AM
visph
visph - avatar
+ 2
visph Martin Taylor It worked!!👍👍. I successfully created a txt file in my internal storage
31st May 2021, 7:16 AM
Muhd Khairul Amirin
Muhd Khairul Amirin - avatar
+ 1
if you run your code in sololearn playground, then it is executed on sololearn servers, so you try to access their local file system, not your phone file system ^^
30th May 2021, 7:26 AM
visph
visph - avatar
+ 1
visph How to specify path of a file in an Android phone?đŸ€”
30th May 2021, 8:32 AM
Muhd Khairul Amirin
Muhd Khairul Amirin - avatar
+ 1
visph 😅 If the file is in the internal storage?đŸ€”
30th May 2021, 8:46 AM
Muhd Khairul Amirin
Muhd Khairul Amirin - avatar
0
Use Java n-ide not available on playstore
16th Dec 2022, 2:44 AM
Rapheal Oluwabukola Rotimi (PRO)
Rapheal Oluwabukola Rotimi (PRO) - avatar