This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes How to read a file, then select a line and use what comes after the selected characters. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to read a file, then select a line and use what comes after the selected characters." Watch "How to read a file, then select a line and use what comes after the selected characters." New topic
Author

How to read a file, then select a line and use what comes after the selected characters.

matthew christensen
Greenhorn

Joined: Sep 14, 2010
Posts: 17
So I'm writing a simple event logging program for my game. But I have a problem. I have a .properties file. That contains 3 lines of text(lines of text below)



I want to scan the file, then somehow use the data darkened below to set the path, max file size, and the save path.

max-file-size=15
log-path=C:\LWLW\
log-file-name=LWLog.txt


How would I go about doing this? I tried google for answers but alas nothing came of my search. Thanks guys!
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

If you were going to describe the bolded part in English, how would you do that?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

No, actually you said you have a .properties file. So you don't have to parse it yourself (which is what I was mistakenly getting at in my previous post). Just create a Properties object to read that file and extract the properties from it. (You'll have to format it correctly, though, I think the backslash has a special meaning in a .properties file, check that out.)
matthew christensen
Greenhorn

Joined: Sep 14, 2010
Posts: 17
What do you mean by a properties object?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37900
    
  22
Start here: Java Tutorials
matthew christensen
Greenhorn

Joined: Sep 14, 2010
Posts: 17
Campbell Ritchie wrote:Start here: Java Tutorials


Thanks! got it to work!
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37900
    
  22
You’re welcome and well done.
matthew christensen
Greenhorn

Joined: Sep 14, 2010
Posts: 17
Here's the code if anyone is interested!

Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37900
    
  22
Thank you for showing us that.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to read a file, then select a line and use what comes after the selected characters.
 
Similar Threads
How to make a data source connection without writing a User name & Password and the -ds.xml file
How to read properties file in netbeans?
Jboss can not recognize custom log4j.properties file
DailyRollingFileAppender
To detect block moves