Skip to content

Instantly share code, notes, and snippets.

@cyberterror
Created September 25, 2016 18:43
Show Gist options
  • Save cyberterror/510cca0fbb0423d5f3c68fc92bb87a0f to your computer and use it in GitHub Desktop.
Save cyberterror/510cca0fbb0423d5f3c68fc92bb87a0f to your computer and use it in GitHub Desktop.
package com.cyberterror;
import java.io.*;
public class Main {
public static void main(String[] args) {
/** Формат ввода :
* [файл для чтения] [файл для записи] [номер столбца] */
if (args.length != 3) {
CommonUtils.print_error("Неверный запрос");
CommonUtils.print_info("java -jar TextParser.jar [файл для чтения] [файл для записи] [номер столбца] ");
System.exit(1);
}
File input = new File(args[0]);
File output = new File(args[1]);
int tableColumnIndex = Integer.parseInt(args[2]) - 1;
String outputString = "";
/** Читаем файл построчно*/
try (BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(input)))) {
String line;
while ((line = reader.readLine()) != null) {
/** Делим каждую строку " | " и печатаем нужный номер столбца */
outputString += line.split(" \\| ")[tableColumnIndex]+"\n";
}
} catch (IOException e) {
e.printStackTrace();
}
CommonUtils.print_good("RESULT");
System.out.println(outputString);
try (FileOutputStream outputStream = new FileOutputStream(output)){
outputStream.write(outputString.getBytes());
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment