I need a quick tip on using new File(File dir, String file). I’m specifically dealing with Android and am not concerned with any other systems. I only bring up Android because of the linux-based OS, so I think it might make a difference.
I want to make a new directory named “original” on the sdcard in the “uot” directory. So the path would be: "/sdcard/uot/original/"
I’m also wanting to call new File(systemDir, "framework-res.apk")
My question, simply:
Do I need path separators in the String part of new File(File dir, String file) or not?
EDIT:
I’m wanting to then call mkdirs() on the new File that I create above.
To make a new directory, which should I do:
File newDir = new File(sdcard, "/uot/");
newFile.mkdirs();
or
File newDir = new File(sdcard, "uot");
newFile.mkdirs();
And then for newFile I’m going to then call
"cp "+newFile.getAbsolutePath()+" "+newDir.getAbsolutePath()
To generate the File object for newFile, should I do:
File newFile = new File(systemDir, "framework-res.apk");
or
File newFile = new File(systemDir, "/framework-res.apk");
Note:
systemDir will point to “/system/”, but I already have that resolved separately.
No. You can add them or not add them. The point of that constructor is so it’s easier to constructor File references without hard coding platform dependent separators in your program. So if you have a parent File you can create references to children without the need to specify separators:
See there we didn’t use any separators between the parent file and the child. Another option for platform independence you can do this:
In which case this is parentPath is a String. Finally the second argument could be a any sub-path relative to parentFile: