if i have a text file with data:
test, 1, 2
again, 3, 4
Can someone give me an idea how to start puting each line into an object ?
ObjectName o = new ObjectName(String s1, String s2, String s3);
class Action implements ActionListener {
public void actionPerformed (ActionEvent e) {
File file = new File("test.txt");
StringBuffer contents = new StringBuffer();
BufferedReader reader = null;
try
{
reader = new BufferedReader(new FileReader(file));
String text = null;
// repeat until all lines is read
while ((text = reader.readLine()) != null)
{
contents.append(text).append(System.getProperty("line.separator"));
}
} catch (FileNotFoundException e)
{
e.printStackTrace();
} catch (IOException e)
{
e.printStackTrace();
} finally
{
try
{
if (reader != null)
{
reader.close();
}
} catch (IOException e)
{
e.printStackTrace();
}
}
// show file contents here
// System.out.println(contents.toString());
}
}