Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.File;
- import java.io.FileWriter;
- import java.io.Writer;
- import java.util.Scanner;
- public class RemoveSameLines {
- public static void main(String[] args) {
- if (args.length < 2) {
- System.out.println("IN_FILE OUT_FILE");
- System.exit(1);
- }
- Scanner in = null;
- Writer out = null;
- String prev = "";
- try {
- in = new Scanner(new File(args[0]));
- out = new FileWriter(new File(args[1]));
- StringBuffer sb = new StringBuffer();
- while (in.hasNextLine()) {
- String cur = in.nextLine();
- if (prev.equals(cur)) continue;
- sb.append(cur);
- sb.append("\n");
- prev = cur;
- }
- out.write(sb.toString());
- }
- catch (Exception e) {
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement