1
    private void view() throws IOException {
    // TODO Auto-generated method stub

    viewframe=new JFrame("#Customer Accounts#");
    viewframe.setSize(600,350);
    viewframe.setVisible(true);
    viewpanel=new JPanel(new BorderLayout());
    viewframe.add(viewpanel);

    int i=0;
    String data[][]=new String[100][100];
    String col[]={"Account Number","First Name", "Last Name", "Balance","Overdraft"};
    Boolean eof=false;
    try {
        datain=new DataInputStream(new FileInputStream("creditunion.txt"));

        while(!eof)
        {
            try{
                while(true)
                {
                    for(int j=0;j<=3;j++)
                    {
                        data[i][j]=datain.readUTF();
                    }
                    i++;
                }

            }catch(EOFException e)
            {
                eof=true;
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        datain.close();
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    viewtable=new JTable(data,col);
    scrollpane=new JScrollPane(viewtable);
    viewpanel.add(scrollpane);
}

 java.io.UTFDataFormatException: malformed input around byte 59
at java.io.DataInputStream.readUTF(Unknown Source)
at java.io.DataInputStream.readUTF(Unknown Source)
at CreditUnion.CreditUnion.view(CreditUnion.java:156)
at CreditUnion.CreditUnion.actionPerformed(CreditUnion.java:109)
at java.awt.Button.processActionEvent(Unknown Source)
at java.awt.Button.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$200(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

嗨,大家好。我得到一个 UTFDataFormatException 并且无法弄清楚是什么原因。我似乎能够毫无问题地将数据写入 txt 文件,并且可以看到文件本身中出现了数据。

4

0 回答 0