So I am writing a program to read text from a file. Save from an array list to an array and then parse that array for ',' and use that to change words position in the 2d array i will write from the 1d array. So essentially String[]{"a,b,c","d,e,f"} ought to save to String[][]{{"a","b","c"},{"d","e","f"}}. but a null char is being added to the begenning ie: String[][]{{"nulla","nullb","nullc"},{"nulld","nulle","nullf"}}. This needs to be a 2d array so that i can place it into a JTable
Heres my code, I simply do not see what is happening here.
public String[][] getDat()
{
ArrayList<String> dataAL = new ArrayList<String>();
try
{
Scanner file = new Scanner(new File ("dat.csv"));
while (file.hasNext())
{
dataAL.add(file.nextLine());
}
file.close();
}
catch (FileNotFoundException fnfe)
{
System.out.println("File Not Found");
}
catch (Exception e)
{
e.printStackTrace();
}
String[] data = new String[dataAL.size()];
dataAL.toArray(data);
String[][]newData=new String[dataAL.size()][dataAL.size()];
int k=0;
for(int i=0; i<data.length;i++)
{
for(int j=0; j<data[i].length();j++)
{
if(data[i].charAt(j)==',')
{
k++;
}
else
{
newData[i][k]+=data[i].charAt(j);
}
}
k=0;
}
return newData;
}