2

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'

2
  • How about declaring the variables before using them? Commented Nov 13, 2014 at 17:19
  • You havent declared out or in Commented Nov 13, 2014 at 17:19

6 Answers 6

7

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){
    }
}   
Sign up to request clarification or add additional context in comments.

Comments

6

In order to define variables you must give them types, e.g.:

OutpustStream out = new DataOutputStream(new BufferedOutputStream(new FileOutputStream("dec.dat")));
InputStream in = new DataInputStream(new BufferedInputStream(new FileInputStream("enc.dat")));

Comments

3

You have not actually declared anything as in or out.

DataInputStream in =

DataOutputStream out =

Comments

2

This should work.

package javaapplication32;
import java.io.*;

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

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

Comments

0

You need to declare in and out as something first!

DataInputStream in =

DataOutputStream out =

E.g.

out = new DataOutputStream(new BufferedOutputStream(new FileOutputStream("dec.dat")));
    in = new DataInputStream(new BufferedInputStream(new FileInputStream("enc.dat")));

Comments

-3

In Java, Pre Initialisation of strings is mandatory. Only then you can use them inside a program. Easiest way to do this is:

String in="";
String out="";

You should be fine...

1 Comment

Sorry, this is plain nonsense. in and out aren't Strings, they are Input/Output streams. And it is not about initialisation, but about declaration. Your answer adds nothing new. And worse: it only adds wrong information.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.