FileWriter抛出一个numberformatexception

时间:2013-09-08 17:00:57

标签: java filewriter numberformatexception

                if (bsave == e.getSource()) {
        path=null;
        try {
            getpath();
        } catch(Exception ee) {
            JOptionPane ss=new JOptionPane();
            ss.showMessageDialog(this,"Something wrong with the path....maybe Chinese name....");
        }
        if (path==null) return ;
        setTitle(path);
        try {
            File file=new File(path);   
            if(!file.exists()) file.createNewFile(); 
            FileWriter fw = new FileWriter(path,true);
            BufferedWriter bw = new BufferedWriter(fw);
            String myreadline=textf.getText();
            if (ty==0) {
                if (fw==null) System.out.println(fw);
                System.out.println(ty);
                bw.write(myreadline);
            } if (ty==1) {
                int len=myreadline.length();
                for (int i=0;i<len;i+=8) {
                    bw.write((char) chan.parseInt(myreadline.substring(i,i+7),2));
                }
            } else {
                int len=myreadline.length();
                for (int i=0;i<len;i+=2)
                    bw.write((char) chan.parseInt(myreadline.substring(i,i+1),16));
            }
            br.close();  
            fr.close();
        } catch(Exception e0) {
            System.out.println(e0.toString());
        }           
    }   

总的来说就是这样...但是因为它输出了一个&#34; 0&#34;所以它必须在那里?

java.lang.NumberFormatException:对于输入字符串:&#34; T&#34; &#34;

字符串myreadline以&#34; T&#34;开头。 所以它试着将它改成一个数字......同时写作? 我真的很困惑..

1 个答案:

答案 0 :(得分:0)

如上文所述,FileWriter不会抛出NumberFormatException。检查bw.write((char) chan.parseInt(myreadline.substring(i,i+7),2));周围的代码。在这里,您将从String解析为整数。

最简单的调试方法是在try-catch(RuntimeException){}块中包围这些行并仔细检查异常堆栈跟踪。