Hi an greetings !
I am trying to read a csv file, here's my code, can someone tell me where's the problem cause I can't understand the exception, (sorry for bad english )
package Leitura; import java.io.DataInputStream; import java.io.IOException; import java.io.ObjectInputStream; import java.util.Scanner; import java.util.StringTokenizer; public class LeitorCSV { static LeitorCSV LerCSV(ObjectInputStream in) throws IOException { return new LeitorCSV( in.readUTF(), in.readUTF(), in.readUTF(), in.readUTF(), in.readUTF()) ; } private String num_aluno; private String Freq_Ant; private String Freq; private String Exame; private String Resultado; public LeitorCSV(String a,String b,String c,String d,String e) { this.num_aluno=a; this.Freq_Ant=b; this.Freq=c; this.Exame=d; this.Resultado=e; } public static LeitorCSV LerCSV(DataInputStream in) throws IOException { return new LeitorCSV( in.readUTF(), in.readUTF(), in.readUTF(), in.readUTF(), in.readUTF()) ; } }
in the main here is :
package Leitura; import java.io.*; import java.util.LinkedList; public class TesteLeitor { private static String ficheiro = "C:\\csv_file.csv"; public static void main(String[] args) throws IOException,ClassNotFoundException { FileInputStream file = new FileInputStream(ficheiro); ObjectInputStream in = new ObjectInputStream(file); LinkedList <LeitorCSV> L = new LinkedList<LeitorCSV>(); while( file.available() > 0 ) { L.add(LeitorCSV.LerCSV(in)); } in.close(); System.out.println("Leitura concluida..."); for (LeitorCSV c : L) { System.out.println( c.toString() ); } } }
note: I got some imports not used cause I am separating the problem first. once I solve this one I will go to the next