Sanil Khurana
Sanil Khurana

Reputation: 1169

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'

Upvotes: 2

Views: 352

Answers (6)

ASK Arjun
ASK Arjun

Reputation: 123

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...

Upvotes: -3

Alex
Alex

Reputation: 376

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")));

Upvotes: 0

Ashiq Imran
Ashiq Imran

Reputation: 2311

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

Upvotes: 2

subash
subash

Reputation: 3115

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

Upvotes: 7

user1231232141214124
user1231232141214124

Reputation: 1349

You have not actually declared anything as in or out.

DataInputStream in =

DataOutputStream out =

Upvotes: 3

Mureinik
Mureinik

Reputation: 312249

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")));

Upvotes: 6

Related Questions