package pl.dmcs; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; public class FileConverter { public void convertToUpperCase(String filePath) throws IOException { Path originalPath = Paths.get(filePath); Path tempFilePath = Paths.get("target/test-classes/file.tmp"); try (BufferedReader reader = new BufferedReader(new FileReader(originalPath.toFile())); BufferedWriter writer = new BufferedWriter(new FileWriter(tempFilePath.toFile()))) { reader.lines() .map(String::toUpperCase) .forEach(line -> { try { writer.write(line); writer.newLine(); } catch (IOException e) { throw new RuntimeException(e); } }); } Files.delete(originalPath); Files.move(tempFilePath, originalPath); } }