Java:调用WriteUTF方法出错



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

`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)"的错误。

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

你可能应该声明outstreamDataOutputStream引用:

DataOutputStream outstream;

作为writeUTF的方法是为DataOutputStream定义的

相关内容

  • 没有找到相关文章

最新更新