on 05-30-2008 11:50 AM
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();
}
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
83 | |
10 | |
10 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.