基本java代码出错

时间:2014-11-13 17:18:26

标签: java compiler-errors inputstream outputstream

这是一些基本的java代码:

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

我收到的错误是它无法在'中找到符号'或者' out'

6 个答案:

答案 0 :(得分:6)

为了定义变量,你必须给它们类型,例如:

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

答案 1 :(得分:6)

您应该先申报。

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

答案 2 :(得分:3)

您实际上并未声明inout

DataInputStream in =

DataOutputStream out =

答案 3 :(得分:2)

这应该有效。

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

答案 4 :(得分:0)

你需要首先声明进出!

DataInputStream in =

DataOutputStream out =

<强> E.g。

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

答案 5 :(得分:-3)

在Java中,字符串的预初始化是强制性的。只有这样你才能在程序中使用它们。最简单的方法是:

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

你应该没事......