I am trying to get the following code to work properly. It always prints the output from the catch block, even though the output that is only printed if the file exists, is printed.
String outputFile = "/home/picImg.jpg";
File outFile = new File(outputFile);
if(outFile.exists)
newStatus(" File does indeed exist");
FileOutputStream fos;
try {
fos = new FileOutputStream(outFile);
fos.write(response);
fos.close();
return outputFile;
} catch (FileNotFoundException ex) {
newStatus("Error: Couldn't find local picture!");
return null;
}
In the code response
is a byte[]
containig a .jpg image from a URL. Overall I am trying to download an image from a URL and save it to the local file system and return the path. I think the issue has to do with read/write permissions within /home/
. I chose to write the file there because I'm lazy and didn't want to find the username to find the path /home/USER/Documents
. I think I need to do this now.
I notice in the terminal I can do cd ~
and get to /home/USER/
. Is there a "path shortcut" I can use within the file name so that I can read/write in a folder that has those permissions?