Software Archive
Read-only legacy content
17061 Discussions

Where to write a file in Tomcat 8 and Servlet /JSP on my Hard Disk ?

Find_N_
Beginner
814 Views

Hi all,

I want to write my.properties file. My query is that “In which path it should be created”. I have installed glassfish on my Linux 14.04 machine on this path: /opt/glassfish4 and created the file my.properties at: /opt/glassfish4/glassfish/domains/swManzana/config/my.properties

This is my Java Code:

Boolean wflag = false;

String wnomfile="my.properties"

Properties prop = new Properties();

OutputStream output = null;

System.out.println("Inicio Archivo Properties.. " + wnomfile);

try {

// output = new FileOutputStream("config.properties");

output = new FileOutputStream(wnomfile);

System.out.println("Archivo Creado Properties..");

// set the properties value

prop.setProperty("database", "localhost");

prop.setProperty("dbuser","mkyong");

prop.setProperty("dbpassword","password");

// save properties to project root folder

prop.store(output,null);

System.out.println("Archivo Creado/Grabado Properties..");

wflag=true;

}catch(IOExceptionio){

System.out.println("Error Archivo Properties Exception..");

io.printStackTrace();

}finally{

System.out.println("Archivo Properties inicio Finally..");

if(output!=null){

try{

System.out.println("Archivo Properties Antes de CLOSE Finally..");

output.close();

System.out.println("Archivo Properties Grabado Finally..");

}catch(IOExceptione){

System.out.println("Archivo Properties Exception-Finally..");

e.printStackTrace();

}

}

}

return wflag;

While executing the above code my.properties file not created. Why Tomcat is not creating this file. I have properly checked my tomcat installation and found no issues in access web Pages and ports.

Can anyone suggest me some knowledgeable tutorials URL Links on Java questions and answers, so that I can get my query resolved faster.

Thanks

0 Kudos
1 Reply
Barry_Johnson
New Contributor I
814 Views

I think there is some confusion here:

a) This forum, about a javascript-based mobile app development platform, is not a useful place to look for guidance on Java application servers.

b) While it has been a year since I have done much with Java, unless the projects have converged (unlikely) Tomcat and Glassfish are two different tools for the same thing: java app servers (Tomcat being simpler, Glassfish being a reference implementation for the Java Enterprise Edition functionality).

You say you are using Tomcat, yet you are installing Glassfish.

Are you getting an error? Are you certain your working directory is what you think it is? Maybe your properties file is being written elsewhere.

0 Kudos
Reply