cancel
Showing results for 
Search instead for 
Did you mean: 

Vector String??

Former Member
0 Kudos

Hello! I have one error!! How can I solve it?? Thanks!!

Vector String[] myVektor = new Vector String[]();

String trennzeichen = ";";

try {

BufferedReader in = new BufferedReader(new FileReader(new File("test.csv")));

String readString;

while ((readString = in.readLine()) != null) {

myVektor.add(readString.split(trennzeichen));

}

in.close();

} catch (Exception e) {

e.printStackTrace();

}

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hello,

I do not really understand what kind of error you have got. Also the code example is not formatted quite well so it is not really clear what is your code fragment doing.

Basically, String.split(String) returns an array of strings. So your Vector (But why Vector? It is an obsolete synchronized structure, use ArrayList instead!) must be of type:


Vector <String[]> myVektor = new Vector <String[]>(); 

On the other hand, it is not a good practice to close the stream in the try block. The Java programming language provides the keyword "finally" for this purpose:


BufferedReader in = null;
try {
  in = new BufferedReader(new FileReader(new File("test.csv")));
  String readString;
  while ((readString = in.readLine()) != null) {
    myVektor.add(readString.split(trennzeichen));
  }
} catch (Exception e) {
  e.printStackTrace();
} finally {
  if (in != null)
    try { in.close(); } catch (IOException e) { /* you can ignore it */ }
}

Is this okay for you?

Kind regards,

Tsvetomir

Answers (0)