2

Первый метод public static void main(String[] agrs) - точка входа, а второй - реализация задания. У меня реализация в public static void main(String[] agrs), но надо сделать по другому. Вот мой код:

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.PrintWriter;

public class Lab14 {
    public static void main(String[] args){
        try
        {
            FileReader fr = new FileReader("E:\\Java\\14 лабораторная\\src\\com\\example\\Lab14\\file.txt");
            BufferedReader br = new BufferedReader(fr);
            PrintWriter out = (new PrintWriter(new FileWriter("E:\\Java\\14 лабораторная\\src\\com\\example\\Lab14\\mahesh.txt")));
            String s="";
            while((s = br.readLine()) != null)
            {
                out.write(s.toUpperCase()+"\n");
            }
            out.close();
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
    }
}

Вот пример, но другого кода:

public class Task1 {
    public Task1() {
    }

    public static void main(String[] args) {
        printRes("CAFE");
        printRes("my");
        printRes("MY");
        printRes("CATE");
        printRes("ABCD");
        printRes("0");
        printRes("9");
        printRes("10");
        printRes("333");
    }

    public static int hexStringToInt(String s) {
        int res = Integer.parseInt(String.valueOf(s), 16);
        return res;
    }

    static void printRes(String s) {
        System.out.print("s:" + s + " result: ");

        try {
            System.out.println(hexStringToInt(s));
        } catch (IllegalArgumentException var2) {
            System.out.println("EXCEPTION!" + var2.getMessage());
        }

    }
}
1
  • Что бы сделать по другому надо написать что именно и как именно.
    – Roman C
    10 дек 2018 в 13:32

1 ответ 1

1

?

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.PrintWriter;

public class Lab14 {
    static void copyFileAsUpper(String fileNameFrom, String fileNameTo) {
        try
        {
            FileReader fr = new FileReader(fileNameFrom);
            BufferedReader br = new BufferedReader(fr);
            PrintWriter out = (new PrintWriter(new FileWriter(fileNameTo)));
            String s;
            while((s = br.readLine()) != null)
            {
                out.write(s.toUpperCase()+"\n");
            }
            out.close();
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        copyFileAsUpper(
            "E:\\Java\\14 лабораторная\\src\\com\\example\\Lab14\\file.txt",
            "E:\\Java\\14 лабораторная\\src\\com\\example\\Lab14\\mahesh.txt"
        );
    }
}

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.