How to read a property file..urgent

Hi ,
This is kinda urgent if you can help! I am a new bee to servlet and java.
My JSP calls a java class file. In the class file i establish my connection to database.
My requirement is to read a property file for the database name, username and password and connet to the database using JDBC(database is oracle).
which class to use. I know something about properties class. Is there any other class which can read my property file.
Or is there any other all together a better way to do it.
thanks in advance
Amit

Inside your WAR file somewhere under the WEB-INF directory. This space is protected, whereas the ROOT (of course) is not. Unless you would like someone else to read your properties file...
Once you decide where you want it, post the section of code where you load the properties file, we can probably help you figure out where you path is wrong.

Similar Messages

  • How will read the property file on dynamically?

    hi,
    I developed 2 java files...in both the files i am reading the some content from .property file(Notes.properties)....
    I created the jar file call Aix.jar using the following command.
    jar -cvf Aix.jar *.class(without specifying the notes.properties file)...
    then i executed the java file using the folowing command
    java -cp Notes.jar;Aix.jar NotesToolTest
    now i am getting following exception:
    Exception in thread "main" java.lang.ExceptionInInitializerError
    Caused by: java.util.MissingResourceException: Can't find bundle for base name Notes, locale en_US
    at java.util.ResourceBundle.throwMissingResourceException(Unknown Source)
    at java.util.ResourceBundle.getBundleImpl(Unknown Source)
    at java.util.ResourceBundle.getBundle(Unknown Source)
    at NotesToolTest.<clinit>(NotesToolTest.java:28)
    I got the problem why this happening...because notes.properties is not included in jar file...that's why the above exception is coming.
    But my problem is can i run the java file that will take .prooperties file dynamically(if .property is available on the current directory)...
    Thanks in advance,,,,
    Regards,
    Sankar

    because notes.properties is not included in jar file..Wrong. It is simply not available in the classpath.
    The solution is either putting the properties file in the classpath of JVM used, or adding the system path to the propertiesfile to the classpath of the JAR.

  • How to add the property file..ie(default.properties) to a webdynpro project

    Hi All,
    How to add the property file..ie(default.properties) to a webdynpro project.
    I urgently require the solution. Kindly get it for me.
    Regards
    DK

    Hi DK,
    this is described in the second Web Dynpro Java Tutorial
    <a href="https://www.sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/sdn/downloaditem?rid=/library/uuid/b1a3e990-0201-0010-aeb2-a2ef5bc3da8e">creating an Extended Web Dynpro Application</a>
    Regards, Bertram

  • Read a property file and store it in a hashmap

    Hi,
    I have tried to read a property file and store it in a hashmap. The property-names should be stored in keys and the property-values (after = symbol) in values of the hashmap. any ideas? Is it possible to do this?

    mandy2001ir wrote:
    yes, but I need the hashmap for another reason. Actually I'm trying to use the properties file to have a dynamic hachmap. I don't want to change the code anytime I want to put a value in the hashmap. therefor I write the "keys" and "values" in a property file and change the property file. That's the reasn why we have property files, isn't it?What's a "dynamic hashmap"? There's no other kind! Whenever someone starts bandying around the word "dynamic" in contexts like this, it usually means there's a simple solution to their problem, that they haven't yet considered, or mistakenly don't believe is applicable to them, because of this "unique" need for something "dynamic". Trust me, you just need to load the file using a Properties object, and you're done. Properties extends Hashtable, which is virtually the same thing as a HashMap. Properties does exactly what you want it to. it's the very reason the class exists
    Have you even looked at the javadoc for java.util.Properties yet? I'm betting not, because if you had, you'd know exactly what I meant. And since you haven't, I'm at a bit of a loss as to how you can so easily dismiss the class as useless, despite existing to do exactly what you need

  • How to Read a CAB File from JAVA?

    Hi,
    Anyone knows how to read a CAB File from java. I need to read a property file of txt file that is packaged in CAB file & then based on that, I have to do processing. Is there anyway to do it.
    I had tried using java.util.zip.ZipFile Class, but it does work for JAR, but not for CAB.
    siva.

    Perhaps there's something in the Cabinet SDK that will help:
    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dncabsdk/html/cabdl.asp

  • How to read the properties file available in Server File structure in webdy

    hi all,
    I have developed one webdynpro application. In this application i need to access mdm server to continue. For getting the connection i need to pass the IP addresses.
    Can i have code  how to read the properties file which is residing in the server file. with out included along with the application. keeping some where in the file structure in the server. I want to read that properties file by  maintain the iP addresses and users in  properties file based on the key i want to read like below.
    servername="abcServer"
    username="john"
    password="test123"
    Please send me the code how to read this properties file from the file structure and how to read this values by key  in webdynpro application
    Regards
    Vijay

    Hi Vijay,
    You can try this piece of code too:
    Properties props = new Properties();
    //try retrieve data from file
    //catch exception in case properties file does not exist
    try {
             props.load(new FileInputStream("c:\property\Test.properties")); //File location
             String serverName = props.getProperty("servername"); //Similarly, you can access the other properties
             if(serverName==null)
               //....do appropriate handling
         }     catch(IOException e)
                   e.printStackTrace();
    Regards,
    Alka.

  • Read a property file !

    Hi all,
    i have to read a property file; i put it under the directory WEB-INF/classes so i can read it using the classloader.
    This works fine under Tomcat, but when i put my webapplication under SunONE, i must put this file under the directory /server1/config.......how cai force the system to read the file from the WEB-INF/classes directory without specifing an absolute path ?
    Cheers.
    Stefano

    There are a couple of ways, but you need the ServletContext object.
    ServletContext.getRealPath("websitePath")
    ServletContext.getResourceAsStream("websitePath")
    The first method converts a website relative path to a location on disk - eg /config -> c:\tomcat\webapps\myApp\config
    The second actually opens a file at that location, and returns an input stream to it.
    The second can be more portable, because if the container you are using does not "explode" the WAR file, the path returned refers to the target within the WAR file - and the java.io functions don't handle that case.
    Cheers,
    evnafets

  • How can you change property files of a EJB at Runtime?

    Hi,
    I have got an ejb and want to change my variables which I stored in property file at Runtime.
    But the property file isn´t in the jar-file of my ejb...
    How can I add it.
    Or How can I change the property file without new compilation.
    Thanks
    Uli

    Hi Uli,
    the previous post is generally correct, but without taking any part in the sensibility of this (there are valid reasons why you would not store the values in a DB) it would be necessary for you to be a bit more specific.
    Is your problem that you can not see the file from your EJB or that you don't know how to change a property file entry in general?
    Cheers,
    Kalle

  • How to read several text files at a time

    Dear all
          Read and write one text file is not a problem, but  what confusies me is how to read several text files at one time, in the meanwhile,
    is it possible to display the name of the text file?
    For example, assuming I want to load file" cha 1, cha 2 , cha 3, " at one time and show their names, how to hadle with it
    I have reviewed some files and it is not helpful

    Either with a 'for' loop like in the lib you have attached, or like this attached VI
    that's it
    Message Edited by devchander on 05-30-2006 05:11 AM
    Attachments:
    MULTIPLE READ.vi ‏44 KB

  • In Vista,  Applet isn�t able to read the property files

    I�m working on internationalization; the Applet which I�m using wasn�t able to read the property files properly in windows Vista machine. But if I create a jar which contains all the classes and property files, Applet works fine.
    This problem is only in Vista machine ,In XP the JVM is smart enough to read plain .property files and its works well without creating the jar
    Is that related to any security enhancemence of vista over XP?
    Below is a link about The Java Security Model break on Windows Vista
    http://bugs.sun.com/view_bug.do?bug_id=6548078
    I tried a simple ResourceBundle.getBundle() in my Applet in different ways but nothing work fine for me. It isn�t an issue related to path, I guess because I tried several ways like.
    ResourceBundle labels = ResourceBundle.getBundle("LabelsBundle");
    ResourceBundle labels = ResourceBundle.getBundle("LabelsBundle",currentLocale);
    ResourceBundle labels = ResourceBundle.getBundle("com.test.LabelsBundle");
    ResourceBundle labels = ResourceBundle.getBundle("com.test.LabelsBundle",currentLocale);The exception got in java console is
    CONFIG: [2008-05-13 15:54:57.909]:(com.satm.insite.InsiteApplet$2@1696e4c):InisiteApplet: Exception:  java.util.MissingResourceException: Can't find bundle for base name LabelsBundle, locale en
    java.util.MissingResourceException: Can't find bundle for base name LabelsBundle, locale en
                at java.util.ResourceBundle.throwMissingResourceException(Unknown Source)
                at java.util.ResourceBundle.getBundleImpl(Unknown Source)
                at java.util.ResourceBundle.getBundle(Unknown Source)
                at com.satm.insite.InsiteApplet.displayValue(InsiteApplet.java:261)
                at com.satm.insite.InsiteApplet.callme(InsiteApplet.java:296)
                at com.satm.insite.InsiteApplet.initialize(InsiteApplet.java:327)
                at com.satm.insite.InsiteApplet$2.run(InsiteApplet.java:235)
                at com.satm.tools.languageTools.ThreadPool$ExceptionCatchingThread.run(ThreadPool.java:226)Is there any way to make it work in Windows Vista machine�? This could be a great help for me.
    Thanks
    Robert

    Crossposted:
    http://forum.java.sun.com/thread.jspa?threadID=5295743&messageID=10250558#10250558
    http://forum.java.sun.com/thread.jspa?threadID=5295742&messageID=10250556#10250556

  • Error while reading a property file from a war.

    Hi,
    I am trying to read a property file which is available in the properties folder.
    The piece of code that does this read is as follows.
    InputStream is = ClassLoader.getSystemResourceAsStream("codemap.properties");
    System.out.println("Reading file:"+is);
    properties.load(is);
    The "codemap.properties" file is available in the properties folder.
    Following is my directory structure in the war file
    sample.war
    |
    |
    WEB-INF
    |
    |
    classes
    |
    |
    properties
    |
    |______ codemap.properties
    Inside the war file I have WEB-INF and properties folder.
    Inside WEB-INF i have the classes folder which has the classes
    Inside the properties folder I have the codemap.properties file.
    I am using Jboss. In the class path I have ./properties
    I have also added this classpath in the manifest file.
    Problem: The piece of code that I have written to read the property file is not able to locate the file and this it returns null.
    I am not sure what i am missing here.
    If anyone there have any solutions please let me know.
    Thanks in Advance
    Balaji.

    I think you've to change this line
    InputStream is = ClassLoader.getSystemResourceAsStream("codemap.properties");with this.
    InputStream is = ClassLoader.getSystemResourceAsStream("properties/codemap.properties");it is unable to find the path you specified. by default it'll check the WEB-INF directory. so you've to give the relative path to it.
    Diablo

  • How to read multiple dat files.

    Hello Everyone!
    I am working on a project that requires one file that creates a JFrame with a current file title, JTextFields that accesses two .dat files and a JButton.
    The user clicks a JButton to cycle through the first sequential .dat file. When the end of the first file is reached the file is closed, the JFrame title is changed to the second file title as the user continues to click the JButton to continue on viewing the second file?s records, until the second reaches the end of file.
    The project requires using Try-Catches to catch the EOF exceptions and IOExceptions and Thread or Runnable.
    I have been able to get one file to read and display its records; however, researching back through my text on how to read/write to files I haven?t been able to determine how to get to the end of the file and proceed to the next file without triggering the EOFException. I have even tried multiple Try-Catches (one for each file within the actionPerformed method) and that ends up ignoring the first file records and only displays the second files records.
    This is a school project and we have only covered just the bare basics of Java over the last two months. So, any hints that anyone can provide can only be of what type of procedure will be needed or what procedure won?t help to complete the task, without giving away the solution.
    I have spent approximately 40 hours of study time on this project and believe that I have definitely run into a major snag.
    The following is the code I have so far:
    import java.io.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class StudentRead extends JFrame implements ActionListener
       private JLabel gradStudentList = new JLabel("GRADUATE Student List");
       private JLabel undergradStudentList = new JLabel("UNDERGRADUATE Student List"); 
       private Font bigFont = new Font("Helvetica", Font.ITALIC, 24);
       private JLabel userprompt = new JLabel("View the students");
       private JTextField idNumText = new JTextField(4); 
       private JTextField lastNameText = new JTextField(15);
       private JTextField firstNameText = new JTextField(15);
       private JButton viewRecordButton = new JButton("View Record");
       private JLabel idNumberLabel = new JLabel("ID Number"); 
       private JLabel lastNameLabel = new JLabel("Last name"); 
       private JLabel firstNameLabel = new JLabel("First name");
       private Container con = getContentPane();
       DataInputStream gradStudentInStream;
       DataInputStream undergradStudentInStream;
       public StudentRead()
          super("Read Student Records");
          try
             gradStudentInStream = new DataInputStream(new FileInputStream("GradStudents.dat"));
             undergradStudentInStream = new DataInputStream(new FileInputStream("UndergradStudents.dat"));
          catch(IOException e)
             System.err.println("File not opened");
             System.exit(1);
          setSize(325, 200);
          con.setLayout(new FlowLayout());
          gradStudentList.setFont(bigFont);
          con.add(gradStudentList);
          con.add(userprompt);
          con.add(idNumberLabel);
          con.add(idNumText);
          con.add(lastNameLabel);
          con.add(lastNameText);
          con.add(firstNameLabel);
          con.add(firstNameText);
          con.add(viewRecordButton);
          viewRecordButton.addActionListener(this);
          setVisible(true);
          setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
       public void actionPerformed(ActionEvent e1)
          String lastName, firstName;     
          int IdNum;
          try
             IdNum = gradStudentInStream.readInt();      
             lastName = gradStudentInStream.readUTF();
             firstName = gradStudentInStream.readUTF();
             idNumText.setText(String.valueOf(IdNum));
             lastNameText.setText(lastName);
             firstNameText.setText(firstName);
          catch(EOFException e2)
             closeFile();
             System.exit(0);
          catch(IOException e3)
             System.err.println("Error reading file");
             System.out.println("out");      
             System.exit(1);
       public void closeFile()
          try
             gradStudentInStream.close();
             System.exit(0);
          catch(IOException e)
             System.err.println("Error closing file");
             System.exit(1);
       public static void main(String[] args)
          StudentRead rsr = new StudentRead();
    }

    deepak_1your.com wrote:
    hi,
    If you want to read a file guarding yourself agianst exceptions....
    check this article.... the code presented in this article might suit your needs...
    [http://1your.com/fusion/infusions/articles/readarticle.php?article_id=17|http://1your.com/fusion/infusions/articles/readarticle.php?article_id=17]
    And how does that help with a DataInputStream?

  • How to read an xml file from headers

    Hi ,
    I am not getting how to read an xml file sent by client device in header to server.
    Thankx.

    There is a getHeader() in HttpServletRequest interface
    String locationURL=request.getHeader("Location");If URL of your file was set in Location attribute of header.
    Edited by: ngpgeeta on Dec 19, 2008 8:03 AM

  • How to read a text file using Java

    Guys,
    Good day!
    Please help me how to read a text file using Java and create/convert that text file into XML.
    Thanks and God Bless.
    Regards,
    I-Talk

         public void fileRead(){
                 File aFile =new File("myFile.txt");
             BufferedReader input = null;
             try {
               input = new BufferedReader( new FileReader(aFile) );
               String line = null;
               while (( line = input.readLine()) != null){
             catch (FileNotFoundException ex) {
               ex.printStackTrace();
             catch (IOException ex){
               ex.printStackTrace();
         }This code is to read a text file. But there is no such thing that will convert your text file to xml file. You have to have a defined XML format. Then you can read your data from text files and insert them inside your xml text. Or you may like to read xml tags from text files and insert your own data. The file format of .txt and .xml is far too different.
    cheers
    Mohammed Jubaer Arif.

  • How to read a text file through pl/sql

    How to read a text file through pl/sql

    pl/sql runs inside the database. so your file also should be on the database server file system for you to be able to read.
    check out UTL_FILE package. This is the database package to read/write files on the database server.

Maybe you are looking for

  • I am having problems rebooting my mid 2009 macbook pro (grey screen other issues), need help!

    I am having problems rebooting, I have experienced the same problem as others with the grey screen but my case is a little different, It started with my mid 2009 macbook pro acting a little slower than normal, the screen would freeze, mouse wouldnt m

  • Adobe 9 opening pdf's from web site

    We recently upgrade to Adobe 9 from 8 and have noticed a slowdown in the time it takes to download and open a pdf from a web page link. Adobe 9 shows a download to a temporary folder pop up before the pdf will open. Adobe 8 did not behave the same wa

  • What is the video format for ipod?

    is it mpeg-4, or H264, or both and why does videora take so long to transcode?

  • 2007 CD2 mini - monitor & TV out?

    Can a CD2 mini drive both a monitor and RCA video out without having to plug things in and out every time? It doesn't matter if it mirrors or spans I am just wondering if I pick one up to replace a G4 tower that can do exactly this that a Mini would

  • Indirectly connecting to internet

    A couple of days ago I received a new laptop from my work ( unfortunately a Dell , but at least it was for free...) and to my surprise it had a wireless card in it. So after a short while I got it connected to my Airport Express base station. But the