Search code examples
javacompiler-errorsinputstreamoutputstream

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'


Solution

  • 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){
        }
    }