I'm supposed to create a java applet project and in that I need to read data from .csv file and put it in a scrollable table. I tried to dothat and i get a FileNotFoundException exception.
Here is my code:
import java.applet.Applet;
import java.awt.BorderLayout;
import java.io.BufferedReader;
import java.io.FileReader;
import java.util.ArrayList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
@SuppressWarnings("serial")
public class Test extends Applet
{
Table table;
public void init()
{
try
{
table = new Table();
}
catch (Exception e)
{
e.printStackTrace();
}
this.add(table);
}
}
class Table extends JPanel
{
private String[][] productList;
private JTable table;
public Table() throws Exception
{
read();
BorderLayout layout = new BorderLayout();
layout.addLayoutComponent(new JScrollPane(table), BorderLayout.CENTER);
setLayout(layout);
}
private void read() throws Exception
{
ArrayList<String[]> list = new ArrayList<String[]>();
try
{
BufferedReader br = new BufferedReader(new FileReader("Products.csv"));
String line = br.readLine();
while ((line = br.readLine()) != null)
{
String[] toBeAdded = line.split(",");
list.add(toBeAdded);
}
}
catch (Exception e)
{
e.printStackTrace();
}
productList = new String[list.size()][3];
for (int i = 0; i < productList.length; i++)
for (int j = 0; j < productList[i].length; j++)
productList[i][j] = list.get(i)[j];
}
}
The products.csv is there in the root folder. I try to read in a normal non swing project and it works but not for this. Can anyone help me?