Reek Reek - 4 months ago 30
Java Question

Azure web app write and read files

I have made a simple Java web app that runs on tomcat to explore azure environment.

I can read files (deployed via FTP to web app's root) from the web app, in a path denoted by HOME environment variable (azure's own env variable, resolves to

D:\home
):

String home = env.getProperty("HOME");

FileInputStream fis;
try {
fis = new FileInputStream(home + "/" + "input.txt");

//...

fis.close();
} catch (IOException e) {
//...
}


But I can't write files to the same path:

String home = env.getProperty("HOME");
File file = new File(home + "/output.txt");

try {
FileOutputStream fos = new FileOutputStream(file, true);

//...

fos.flush();
fos.close();
} catch (IOException e) { //ACCESS DENIED
return "ERROR :" + e.getMessage();
}


above code fails with access denied error.

Can I write persistent files to some path in azure, or do I need a cloud native storage for this?

Answer

You cannot create files directly under %HOME%, but you can created directories. And in there, you can create files. It's only files at the very root that it disallowed.