-4

I have a file, test.txt

outputa
outputb
outputc
outputa
outputb
outputc 

I need output like this:

outputaoutputboutputc 
outputaoututboutputc 

Lines should be broken at each occurence of outputa.

Ashwini
  • 1
  • 2

1 Answers1

-1

Probably not exactly what you want, but this should get you started:

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;

public class FileTransformer {

    public static void main(String args[]) throws IOException {
        String s1 = readFile("test.txt");
        s1 = transform(s1, args[0]);
        writeFile(s1);
    }

    private static String readFile(String fileName) throws IOException {
        return new String(Files.readAllBytes(Paths.get(fileName)));
    }

    private static String transform(String input, String elementToStartNewLine) {
        return input.replace("\n", "").replace(elementToStartNewLine, "\n" + elementToStartNewLine);
    }

    private static void writeFile(String content) throws IOException {
        Files.write(Paths.get("output.txt"), content.getBytes());
    }
}

Usage: java FileTransformer outputa

Johnny Alpha
  • 758
  • 1
  • 8
  • 35