Important alert: (current site time 7/15/2013 3:13:05 PM EDT)
 

VB icon

config

Email
Submitted on: 9/29/1999
By: Petri Kunnari 
Level: Not Given
User Rating: By 3 Users
Compatibility: Java (JDK 1.1)
Views: 19267
 
     Code read optionvalue from file. when i started to program with java i search long time samples to this. here is my sollution. if someone knows better post it here.
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
//**************************************
// Name: config
// Description:Code read optionvalue from file.
when i started to program with java
i search long time samples to this.
here is my sollution.
if someone knows better post it here.
// By: Petri Kunnari
//
// Inputs:you can call method roption( string whatoption , string file )from this class
option-file type:
-------------------------------------
option1=value1
option2=value2
etc....
-------------------------------------
//
// Returns:method roption return optionvalue as String
//
// Assumes:make you own class
for example you whant read integer option called numbers from file file.cfg:
include something like this 
config cfg = new config();
Integer ingr = new Integer(cfg.roption( "numbers" , "file.cfg"));
int number = ingr.intValue();
//
// Side Effects:don't know any!!
//
//This code is copyrighted and has// limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=1682&lngWId=2//for details.//**************************************

// class config 
// Petri Kunnari 1999
// petri.kunnari@oulu.fi
import java.io.*;
import java.util.*;
import java.lang.*;
public class config 
{
	// read option from file
	// returns option value
	public String roption( String what , String file) throws IOException
	{
	String w=what; 
	String f=file; 
	String optionline;
	
	FileInputStream fis = new FileInputStream(f);
	Properties prop = new Properties();	
	prop.load(fis);	
	optionline = prop.getProperty(w);
	//System.out.println(optionline);
	return(optionline);
	}
}


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Not Given category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments

6/24/2000 10:01:29 AMBoycey

This bloody comment only lets you add 1000 word comments.
(If this comment was disrespectful, please report it.)

 
6/24/2000 10:03:19 AMJon Boyce

seing as this boox only lets u add a 1000 characters ive put my comment at visit http://www.reprisal.co.uk/comment.htm
(If this comment was disrespectful, please report it.)

 
10/8/2001 6:52:46 AMRichard Gardner

there were some unhanded exceptions but this was a good piece of code. Here's what I changed:

public String readOption(String key, String filename){
//This method will return an option from a file similar
//to an INI file reader.
String value = "";
FileInputStream fis;
try {
fis = new FileInputStream(filename);
}
catch (FileNotFoundException e)
{
return "File not found";
}
Properties prop = new Properties();
try {
prop.load(fis);
}
catch (IOException e) {
return e.getMessage();
}
return prop.getProperty(key);
}

(If this comment was disrespectful, please report it.)

 
4/6/2004 2:53:17 PM

hello sir i read u r code i have one problem i want to transfer data from .dat file to oracle database
please help
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.