Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error with basic java code

This is some basic java code:

package javaapplication32;

import java.io.*;

public class JavaApplication32 {
    public static void main(String[] args)throws Exception {
        try{
            out = new DataOutputStream(new BufferedOutputStream(new FileOutputStream("dec.dat")));
            in = new DataInputStream(new BufferedInputStream(new FileInputStream("enc.dat")));

            String enc=in.readUTF();
            System.out.println(enc);
        }catch(EOFException e){
        }
    }   
}

I am getting the error that it cannot find the symbol 'in' or 'out'

like image 759
Sanil Khurana Avatar asked Sep 12 '26 13:09

Sanil Khurana


1 Answers

You should declare them first.

public static void main(String[] args)throws Exception {
    DataOutputStream out = null; 
    DataInputStream in = null;
    try{
        out = new DataOutputStream(new BufferedOutputStream(new FileOutputStream("dec.dat")));
        in = new DataInputStream(new BufferedInputStream(new FileInputStream("enc.dat")));

        String enc=in.readUTF();
        System.out.println(enc);
    }catch(EOFException e){
    }
}   
like image 161
subash Avatar answered Sep 14 '26 02:09

subash



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!