i want to split a file. i have this in my file called data.txt:
ab
cd
ef
gh
ij
kl
mn
op
qr
so i have tried some coding. but when i tried to split them but it only read this:
ab
ef
ij
mn
qr
this is my code:
BufferedReader in = null;
try {
in = new BufferedReader(new FileReader(data));
String read = null;
while ((read = in.readLine()) != null) {
read = in.readLine();
String[] splited = read.split("\n");
for (int z = 0; z<splited.length; z++)
System.out.println (splited[z]);
}
} catch (IOException exc) {
System.out.println("There was a problem: " + exc);
exc.printStackTrace();
} finally {
try {
in.close();
} catch (Exception exc) {
}
what is wrong with this code?
readLine()
) ... there's nothing to split (ignoring the other issues you have) – Brian Roach 18 mins ago