Reading/writing a text file in a servlet, where sh

2019-01-15 04:06发布

I have servlet deployed in JBoss. I want to read/write data into a text file based on the client input. Where should this text file be put in the JBoss directory structure?

1条回答
老娘就宠你
2楼-- · 2019-01-15 04:29

There the /data directory is for.

enter image description here


Its absolute path is available by the jboss.server.data.dir system property.

File dataDir = new File(System.getProperty("jboss.server.data.dir"));
File yourFile = new File(dataDir, "filename.ext");
// ...

See also:

Note that you're this way tight-coupling the web application code to a specific server. If you ever want to change servers, keep in mind to change the above code as well to whatever the new server supports (or not).

查看更多
登录 后发表回答