The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
March 2001

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

File IO and string problems

Posted by Yooklid on March 05, 2001 at 11:12 AM

I am writing a small test program to try and find the best way to read in a text file. I have the code below. However, while it compiles, I get a run time error, saying I have a null pointer error at line

Hosts[i] = aLine;

Any help would be appreciated. I have a feeling this one is staring me right in the face.

Thanks!

Yooklid


public class TryRead
{
public static void main(String[] args)
{

String DirName = "f:\\CDPNode";
String FileName = "IPTable.dat";
File myFile = new File(DirName, FileName);
BufferedReader theBuffer = null;
FileReader theReader = null;
String aLine = null;
String[] Hosts = null;
int i = 0;


try {
theReader = new FileReader(myFile);
theBuffer = new BufferedReader(theReader);
System.out.println("Streams Created");
}

catch (IOException e)
{
System.out.println(e);
}

try {
aLine = theBuffer.readLine();
}

catch (IOException e) { System.out.println(e);}
System.out.println("Read IP address: " + aLine);

while ( aLine != null)
{
Hosts[i] = aLine;
i++;

try{
aLine = theBuffer.readLine();
}

catch (IOException e) { System.out.println(e);}
}



Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us