issue in filereading using buffered reader and split method
Solution 1
Making
System.out.println(accounts);
Will call the toString()
method and it will print a string representation of the object
. For that you need a simple function to read Array of strings and the print each string of you List. So with this you will have the access of each element of you List. Hope it Help you.
for (String[] myLine : accounts)
{
// To do the magic
}
Solution 2
You are inserting the whole string array into accounts so I guess that [Ljava.lang.String;@7382f612
is the result of the toString() method of the array.
Try accounts.get(0)[0]
for the first field of the first row, accounts.get(0)[1]
for the second field of the first row, etc.
If you want to obtain data as \n Deadra Power \n 009545701 \n Checking \n 4500
then don't split each read line, instead replace commas by \n
.
Solution 3
You are calling System.out.println() on a List.
This calls the System.out.println(Object), which won't know how to recurse into your object.
Have a look at:
How do I print my Java object without getting "SomeType@2f92e0f4"?
You need to get each element out manually and print it.
Solution 4
As Paco Abato pointed out, you are printing the object that is an array of strings.
If you'd like to see each element of the array (i.e. a row from the csv file), you can print it as follows:
for (String[] accountRow : accounts) {
System.out.println(Arrays.toString(accountRow));
}
Related videos on Youtube
ravikiran
Updated on December 06, 2022Comments
-
ravikiran over 1 year
package bankaccountapp; import java.io.*; import java.util.*; public class Csv { public static void main(String args[]){ List<String[]> accounts=new LinkedList<String[]>(); String data; try { BufferedReader br = new BufferedReader( new FileReader( "C:\\Users\\RaviKiran Reddy\\Desktop\\JBNR\\NewBankAccounts.csv")); while ((data=br.readLine())!= null) { String[] datarows=data.split(","); accounts.add(datarows); } } catch (FileNotFoundException e) { e.printStackTrace(); }catch (IOException e1) { e1.printStackTrace(); } System.out.println(accounts); }
When I try to read a CSV file by splitting it using commas I am getting the object code (like
[Ljava.lang.String;@7382f612
) as output, but not the strings as I expected.If this is the line:
Deadra Power,009545701,Checking,4500
then I am expecting the output as:
\n Deadra Power \n 009545701 \n Checking \n 4500
.Can I know where the error is?
-
mnmnc over 11 yearsThis is normally done with Vlans - you can include vlan in the access list and prevent it from using NAT translation. This would be best solution but I dont know if this is possible on Tomato. Im pretty sure though that there is an IPtables [tomatousb.org/forum/t-369359] which could be treated as light weight firewall - you can setup a rule to drop packets based on source and destination.
-
Paco Abato over 5 yearsAs it appears that you got an useful answer you should accept (and maybe upvote) one of them in order to help other people finding correct information.
-
-
ravikiran over 5 yearsyeah,i got it .
-
ravikiran over 5 yearsyeah i got it .
-
ravikiran over 5 yearsyeah i got it now