settingsAccountsettings
Menusettings

Q: ALL CAPITALS - Java Task

+7 votes

Write a program that reads a text file and changes the casing of all letters to upper. The file should be overwritten. Use BufferedReader, FileReader, FileWriter, and PrintWriter.

all capitals letters in Java

asked in Java category by user matthew44
edited by user golearnweb

1 Answer

+1 vote
 
Best answer

Here's my solution, mate:

import java.io.*;
import java.util.ArrayList;
import java.util.List;

public class AllCapitals {
    public static void main(String[] args) throws IOException {
        File lines = new File("resources/linesCapital.txt");

        BufferedReader reader = new BufferedReader(new FileReader(lines));

        String line = reader.readLine();

        List<String> lineArray = new ArrayList<>();

        while (line != null) {
            lineArray.add(line.toUpperCase());
            line = reader.readLine();
        }

        reader.close();

        BufferedWriter writer = new BufferedWriter(new FileWriter("resources/linesCapital.txt"));
        PrintWriter printWriter = new PrintWriter("resources/linesCapital.txt");

        for (int i = 0; i < lineArray.size(); i++) {
            printWriter.println(lineArray.get(i));
//            System.out.println(lineArray.get(i));
        }
        printWriter.close();
        writer.close();

        System.out.println("Good job!");
    }
}
answered by user paulcabalit
selected by user golearnweb
...