Java:调用WriteUTF方法时出错

时间:2013-03-16 14:50:53

标签: java text-files multidimensional-array filewriter

我在将2d用户输入的数组写入文本文件时遇到问题。到目前为止,我的代码(至少在Saving方法中)是:

`public static void Save(String[][] EntryList)
{
   try {
        String[][] content = EntryList;
        File file = new File("CBB.dat");

        // if file doesnt exists, then create it
        if (!file.exists()) {
            file.createNewFile();
        }
        InputStream instream;
        OutputStream outstream;

        instream = new DataInputStream( new BufferedInputStream(new FileInputStream(file))); // buffers the data stream
        outstream = new DataOutputStream( new BufferedOutputStream(new FileOutputStream(file)));
        FileWriter fw = new FileWriter(file.getAbsoluteFile(), true);
        BufferedWriter writer = new BufferedWriter(fw);
        for (int row = 0; row < EntryList.length; ++row)
        {
                outstream.writeUTF(EntryList[row][1]); 
                outstream.writeUTF(EntryList[row][2]);
                outstream.writeUTF(EntryList[row][3]);
                outstream.writeUTF(EntryList[row][4]);
                outstream.writeUTF(EntryList[row][5]);
            }
              outstream.close();

            }catch (IOException e) {
        e.printStackTrace();
    }
        }`

然而,当我尝试编译时,我得到的错误是Java“找不到符号 - 方法WriteUTF(String)”

1 个答案:

答案 0 :(得分:0)

显然没有为java.io.OutputStream定义writeUTF

您应该将outstream声明为DataOutputStream参考:

DataOutputStream outstream;

DataOutputStream定义的方法writeUTF