Question

This is very stupid to ask but I want to know. I have to read a line of text and write in seperate file. I know how to read a line and work on that text but I don't know putting both together. I have a text file with data in it, has header on the top, and I need header on every new file with data from next line on new file. I am able to create logic for that. Please help me.

Was it helpful?

Solution

Lots of examples on web

PrintWriter writer = null;
try {
    writer = new PrintWriter(new FileWriter(new File("pathToNewFile")));

    //do reading etc
    writer.println(stringVariableToWrite);

} catch (IOException e) {
    System.err.println(e);
} finally {
    if (writer != null){
        writer.close();
        if (writer.checkError()) {
             System.err.println(e);
        }
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top