Нет разницы в моей системе:
- Windows Vista SP2 (32-разрядная версия)
- NTFS
- JDK 1.6.0_17
Выход:
Creating C:\workspace\Sandbox\src\data.txt
Reading C:\workspace\Sandbox\src\data.txt
Skipped: 'Months, SEP2010, OCT2010, NOV2010'
First read: 'col1, col2, col3, col4, col5'
Reading C:\workspace\Sandbox\src\data.csv
Skipped: 'Months, SEP2010, OCT2010, NOV2010'
First read: 'col1, col2, col3, col4, col5'
Reading C:\workspace\Sandbox\src\data.txt
Skipped: 'Months, SEP2010, OCT2010, NOV2010'
First read: 'col1, col2, col3, col4, col5'
Код:
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
public class BuffReadTest {
public static void main(final String[] args) {
final String baseFilename = args[0] + "/data";
try {
final File txtFile = new File(baseFilename+".txt");
final File csvFile = new File(baseFilename+".csv");
if (txtFile.exists()) txtFile.delete();
if (csvFile.exists()) csvFile.delete();
createFile(txtFile.getAbsolutePath());
readFile(txtFile.getAbsolutePath());
txtFile.renameTo(csvFile);
readFile(csvFile.getAbsolutePath());
csvFile.renameTo(txtFile);
readFile(txtFile.getAbsolutePath());
} catch (final IOException ex) {
System.out.println("Exception: "+ex);
ex.printStackTrace();
}
}
private static void createFile(final String filename)
throws FileNotFoundException {
System.out.println("\nCreating "+filename);
final PrintWriter pw = new PrintWriter(filename);
pw.println("Months, SEP2010, OCT2010, NOV2010");
pw.println("col1, col2, col3, col4, col5");
pw.println("aaa,,sdf,\"12,456\",bla bla bla, xsaffadfafda");
pw.println("and so on, and so on, \"10,00\", xxx, xxx");
pw.close();
}
private static void readFile(final String filename)
throws FileNotFoundException, IOException {
System.out.println("\nReading "+filename);
final FileInputStream stream = new FileInputStream(filename);
final BufferedReader br = new BufferedReader(new InputStreamReader(stream));
final String skipped = br.readLine();
final String first = br.readLine();
System.out.println("Skipped: '"+skipped+"'");
System.out.println("First read: '"+first+"'");
br.close();
}
}