Simple threads in Java with files

0

I have some text files what they are going to have is simple formulas like 2 + 2, 6 * 90, etc. Each file has to be read by a thread (for each file we will create a thread) that will be responsible for reading the contents of the file and perform the calculations. Finally you should print the result on the screen as something like that should show

Archivo1
2+2
4

I'm implementing it this way

  public class Entrada implements Runnable {

@Override
public void run() {
    FileReader entrada = null;
    try {
        String linea = "";
        entrada = new FileReader("C:/Users/CALCULO1.txt");
        BufferedReader br = new BufferedReader(entrada);
        while ((linea = br.readLine()) != null) {
            System.out.println(linea);
        }

        br.close();
    } catch (Exception e) {

    }
}

public class Salida implements Runnable {

@Override
public void run() {
    FileWriter salida = null;
    try {
        String linea = "";
        salida = new FileWriter("salida.txt");
        BufferedWriter d = new BufferedWriter(salida);


    } catch (Exception e) {

    }
}

public static void main(String[] args) {
    // TODO code application logic here
    Entrada d = new Entrada();
    Thread hilo = new Thread(d);
    hilo.start();
    Salida d1 = new Salida();
    Thread hilo1 = new Thread(d1);
    hilo1.start();
}
    
asked by Sebastian Salazar 23.02.2018 в 20:59
source

0 answers