Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Tomcat and Servlet/JSP where write a file on HDD?

    • 0
    • 0
    • 0
    • 1
    • 0
    • 0
    • 0
    • 367
    Answer it

    hi all i am use tomcat 8 and my war file initially i want write a file a .properties file, here the 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 (IOException io) { 
    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 (IOException e) { 
    System.out.println("Archivo Properties Exception-Finally.."); 
    e.printStackTrace(); 
    } 
    } 
    
    } 
    return wflag; 
    

    my question is, in wich path have been created the file my.properties?

    note my tomcat was installed following this steps: https://www.digitalocean.com/community/tutorials/how-to-install-apache-tomcat-8-on-ubuntu-14-04 and was intalled on /opt/tomcat

    when i run the code the files wasnt created, how to know why? and if created how to know in wich path was created?

    Note: also i installed glassfish on my linux ubuntu 14.04 and immediatly created the file on: /opt/glassfish4/glassfish/domains/swManzana/config/my.properties of course the glassfish is installed on this path: /opt/glassfish4

    and of course created the file

    why in tomcat not create the file?

    tomcat is been installe dnd tested. no problems of access the webpage, and no problem with port access i am sure.

    any advice?

    thanks

 1 Answer(s)

  • It is always a good practice that all property files should be inside root folder of your project. If you do not want to put it in root you can make another directory inside your project directory and put that property file there. The reason to put the property file inside project directory is that it is easily available to use inside the code.

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: