Skip to main content
added 627 characters in body
Source Link
Elmar Brauch
  • 1.4k
  • 9
  • 22

In general you can do it in 3 steps:

  1. Read file and store it in String
  2. Change the String as you need (your "username,password..." modification)
  3. 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(); } }); } } 

In general you can do it in 3 steps:

  1. Read file and store it in String
  2. Change the String as you need (your "username,password..." modification)
  3. Write the String to a file

You can search for instruction of every step at Stackoverflow.

In general you can do it in 3 steps:

  1. Read file and store it in String
  2. Change the String as you need (your "username,password..." modification)
  3. 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(); } }); } } 
Source Link
Elmar Brauch
  • 1.4k
  • 9
  • 22

In general you can do it in 3 steps:

  1. Read file and store it in String
  2. Change the String as you need (your "username,password..." modification)
  3. Write the String to a file

You can search for instruction of every step at Stackoverflow.