Created
September 25, 2016 18:43
-
-
Save cyberterror/510cca0fbb0423d5f3c68fc92bb87a0f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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