Skip to content

Instantly share code, notes, and snippets.

@mad
Created April 24, 2011 18:29
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save mad/939777 to your computer and use it in GitHub Desktop.
Обработка csv файла на Java
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Calendar;
import au.com.bytecode.opencsv.CSVReader;
import au.com.bytecode.opencsv.CSVWriter;
public class Main {
public static void main(String[] args) throws IOException {
if (args.length != 2) {
System.out.println("Specify input and output files");
return;
}
CSVReader reader = new CSVReader(new FileReader(args[0]), '\t');
CSVWriter writer = new CSVWriter(new FileWriter(args[1]), '\t', CSVWriter.NO_QUOTE_CHARACTER);
long begin = Calendar.getInstance().getTimeInMillis();
String[] nextLine;
while ((nextLine = reader.readNext()) != null) {
for (int i = 0; i < nextLine.length / 2; i++) {
int j = nextLine.length - 1 - i;
String temp = nextLine[i];
nextLine[i] = nextLine[j];
nextLine[j] = temp;
}
writer.writeNext(nextLine);
}
System.out.println((Calendar.getInstance().getTimeInMillis() - begin)/1000);
writer.close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment