Is there something wrong with both of your codes or am I doing something wrong? They compile, but when ran, end up outputing the text file verbatim and then crashing with a NullPointerException.
Tampa, try this one, albeit a bit naive, and I've left out the substring for you to figure out.
import java.io.*;
import java.util.*;
public class demo {
public static void main(String args[]) {
String data = null;
int recCount = 0;
try {
FileReader fr = new FileReader("C:\\Development\\demo.txt");
BufferedReader br = new BufferedReader(fr);
data = new String();
while ((data = br.readLine()) != null) {
int length = data.length();
for (int i = 0; i < length; i++) {
System.out.print(data.charAt(i) + " ");
i++;
}
System.out.println("");
data = br.readLine(); // skips a line, which is
// naive, seek something better, but
// you get the idea
recCount++;
}
} catch (IOException e) {
System.out.println("IOException error!");
e.printStackTrace();
}
}
}