I have tried using the startsWith() method but it still reads the line cause an error
public void readDataFromFile() throws Exception
{
// set up an owner for the FileDialog
JFrame jframe = new JFrame();
jframe.setVisible(true);
// use a Filedialog to select a file to read from
FileDialog fDialog = new FileDialog(jframe, "Read from", FileDialog.LOAD);
fDialog.setFile("*.txt");
fDialog.setDirectory(".");
fDialog.setVisible(true);
String fname = fDialog.getFile();
jframe.dispose();
File inFile = new File(fname);
BufferedReader reader = new BufferedReader(new FileReader(inFile));
String line = reader.readLine();
if(line !=null){System.out.println(line);}
while((line=reader.readLine())!=null)
{
if(line.trim().startsWith("#"));
{}
String[] sLine = line.trim().split("\t");
String name = sLine[1];
String species = sLine[2];
addAnimal( new Animal(name,species,this) );
}
reader.close()
}
The text file being read...
import shipment of April 12, 2007
# tab separated data
Bird Golden Eagle Eddie
Mammal Tiger Tommy
Mammal Lion Leo
Mammal Elephant Eddie
Bird Parrot Polly
# last one next
Reptile Cobra Colin

New Topic/Question
Reply




MultiQuote





|