Jump to content
  • Advertisement
Sign in to follow this  
dxFoo

[java] Loading in Properties

This topic is 4769 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I can't seem to load the data from phonebook.dat. I commented where the error is. Any help is great!
import java.lang.*;
import java.io.*;
import java.util.*;

class Console_Practice
{
	public static void main(String args[]) throws IOException
	{ 
		Properties balance = new Properties(); 
		
		// try to open phonebook.dat
		FileInputStream fin = null;
		
		try
		{
			fin = new FileInputStream("c:\\phonebook.dat");
		}
		catch (FileNotFoundException e)
		{
			System.out.println("Error opening file.");
		}
		
		// Load contents of phonebook.dat. ERROR: NOT WORKING HERE
		try
		{
			while (fin != null)
			{
				balance.load(fin);
				fin.close();
			}
		}
		catch (IOException e)
		{
			System.out.println("Error reading file.");
		}
 
 		// Try saving the phone book.
		try 
		{
			FileOutputStream fout = new FileOutputStream("c:\\phonebook.dat");
			balance.store(fout, "Telephone Book");
			fout.close();
		}
		catch (FileNotFoundException e) {}
		
		
	}
}



Share this post


Link to post
Share on other sites
Advertisement
@Son of Cain: dxFoo hasn't written that code: it's a method in the Java API.

@dxFoo: From the code you posted I can't really deduce where the error's coming from. Is this 'phonebook.dat' in a format that Properties expects?
You might find out more about what's going wrong, by printing the detailed message in the exception like this:

catch (IOException e)
{
System.out.println("Error reading file:" + e);
}


Edit: Oh, wait... Try removing the while(fin != null)-loop. If I recall correctly Properties.load reads in the whole file at once.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!