In general you can do it in 3 steps:
- Read file and store it in String
- Change the String as you need (your "username,password..." modification)
- Write the String to a file
You can search for instruction of every step at Stackoverflow.
Here is a possible solution working directly on the Stream:
public static void main(String[] args) throws IOException { String inputFile = "C:\\Users\\geheim\\Desktop\\lines.txt"; String outputFile = "C:\\Users\\geheim\\Desktop\\lines_new.txt"; try (Stream<String> stream = Files.lines(Paths.get(inputFile)); FileOutputStream fop = new FileOutputStream(new File(outputFile))) { stream.map(line -> line += " manipulate line as required\n").forEach(line -> { try { fop.write(line.getBytes()); } catch (IOException e) { e.printStackTrace(); } }); } }