Home arrow static arrow Java Programming [Archive] - loadSettings how do you get the properties from file string
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - loadSettings how do you get the properties from file string
This topic has 9 replies on 1 page.

Posts:37
Registered: 4/28/03
loadSettings how do you get the properties from file string  
May 28, 2004 3:50 PM



 
how do you read properties from file i use this but dosn't work:

public static void loadSettings() {

Properties properties = new Properties();
File file = new File("VWASystem.ini");
FileInputStream fileinputstream = null;

int i;

try {

// Stitle is a String I want to read in

Stitle1 = properties.load(fileinputstream = new FileInputStream(file));

} catch(Exception exception) { return; }

finally {
try { if(fileinputstream != null) {
Stitle1 = "what the!!";
fileinputstream.close();
}
} catch(IOException ioexception1) { }
}
try {
Stitle1 = loadSettings(new File(System.getProperty("Stitle"),));
url1 = String.valueOf(properties.getProperty("url"));

}
// Misplaced declaration of an exception variable
catch(Exception exception) { }

};

threre no errors when I compile it just comes up Null and dont read it from file.
ON MORE when I use System.out.println(" " ); it sats its no such thing any one know why

can any one show me some code how to read properties in and the system.out ? why it doesn't compile?
it did work before and use it before now it dosen't find it


Danmac2760

 

Posts:6,750
Registered: 1/25/04
Re: loadSettings how do you get the properties from file string  
May 28, 2004 4:02 PM (reply 1 of 9)



 
What happens if you move the assignment to its own line?

fileinputstream = new FileInputStream(file)

"when I use System.out.println(" " ); it sats its no such thing any one know why"

What exactly does it say, because I'm sure the compiler or runtime did not say "its no such thing," and guessing at errors messages is not a useful enterprise.
 

Posts:37
Registered: 4/28/03
Re: loadSettings how do you get the properties from file string  
May 28, 2004 4:11 PM (reply 2 of 9)



 
it says can't reslove System.out.println(" what ");

the file i trying to read in has stuff like

String=Welcome my web site
url=203.34.56.12

do you know how to use loadSettings and how would I do that

Thanks
Dan
 

Posts:37
Registered: 4/28/03
Re: loadSettings how do you get the properties from file string  
May 28, 2004 4:12 PM (reply 3 of 9)



 
I used it before and work now it don't damm java :)
any ideas??


Dan

 

Posts:777
Registered: 9/18/03
Re: loadSettings how do you get the properties from file string  
May 28, 2004 4:56 PM (reply 4 of 9)



 
whyy not use ResourceBundle class ??
 

Posts:3,258
Registered: 00-08-28
Re: loadSettings how do you get the properties from file string  
May 29, 2004 11:43 AM (reply 5 of 9)



 
Reading and Writing a Properties File

    // Read properties file.    Properties properties = new Properties();    try {        properties.load(new FileInputStream("filename.properties"));    } catch (IOException e) {    }        // Write properties file.    try {        properties.store(new FileOutputStream("filename.properties"), null);    } catch (IOException e) {    }  


Getting and Setting Properties

    String string = properties.getProperty("a.b");    properties.setProperty("a.b", "new value"); 

Reading and Writing a Properties File

    // Read properties file.    Properties properties = new Properties();    try {        properties.load(new FileInputStream("filename.properties"));    } catch (IOException e) {    }        // Write properties file.    try {        properties.store(new FileOutputStream("filename.properties"), null);    } catch (IOException e) {    }


Here is an example of the contents of a properties file:
# a comment
! a comment

a = a string
b = a string with escape sequences \t \n \r
\" \' \ (space) \u0123
c = a string with a continuation line \
continuation line
d.e.f = another string
 

Posts:1,126
Registered: 10/22/03
Re: loadSettings how do you get the properties from file string  
Jun 23, 2004 6:55 AM (reply 6 of 9)



 
if i have my properties file in the same package as my class, shouldn't the path to my file, just be "myfile.properties" ?

i am having trouble loading the file...it cant find file.
 

Posts:3,258
Registered: 00-08-28
Re: loadSettings how do you get the properties from file string  
Jun 23, 2004 8:17 AM (reply 7 of 9)



 
what error are you getting. Plus it would be a good idea if you could start a new thread with a detailed description of the problem.
 

Posts:1,126
Registered: 10/22/03
Re: loadSettings how do you get the properties from file string  
Jun 23, 2004 8:49 AM (reply 8 of 9)



 
..posted new thread..
 

Posts:6,750
Registered: 1/25/04
Re: loadSettings how do you get the properties from file string  
Jun 23, 2004 9:03 AM (reply 9 of 9)



 
what error are you getting. Plus it would be a good
idea if you could start a new thread with a detailed
description of the problem.

Where do you get off encouraging double-posting?? This is one of the cheif irritants of forum regulars. Unless the thread has wandered irreparably off-topic, I can't see any legitimate reason for starting a new topic unless you just like useless clutter.

<exasperated noise>
 
This topic has 9 replies on 1 page.