I got a text file that has the following
<TAB> is an actual TAB keystroke
US<TAB> United States USA
CA<TAB> Canada CAN
I just wanted to be able to access the 3 elements in each column so I did the following:
import java.io.*;
public class file
{
public static void main(
String[] args)
{
File csv = new File("wl.txt");
try {
DataInputStream in = new DataInputStream(
new FileInputStream("wl.txt"));
DataOutputStream out = new DataOutputStream(
new FileOutputStream("w2.txt"));
char chr;
while (true) {
StringBuffer country_code = new StringBuffer(2);
while ((chr = in.readChar()) != '\t') {
country_code.append(chr);
System.out.println(chr);
}
System.out.println("CC: " + country_code);
StringBuffer country_name = new StringBuffer(20);
while ((chr = in.readChar()) != '\t') {
country_code.append(chr);
}
System.out.println("CN: " + country_name);
StringBuffer district = new StringBuffer(20);
char lineSep = System.getProperty("line.separator").charAt(0);
while ((chr = in.readChar()) != lineSep) {
district.append(chr);
}
System.out.println("D: " + district);
}
}
catch (EOFException e) {
System.out.println(e);
}
// System.
catch (Exception e) {
System.out.println(e);
}
}
}
*************
When I look at the following line, all I see is '?' System.out.println(chr);
What am I doign wrong?