Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/399.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java FileWriter抛出numberformatexception if(bsave==e.getSource()){ path=null; 试一试{ getpath(); }捕获(异常ee){ JOptionPane ss=新的JOptionPane(); showMessageDialog(这是“路径有问题……可能是中文名称……); } if(path==null)返回; 设置标题(路径); 试一试{ 文件=新文件(路径); 如果(!file.exists())file.createNewFile(); FileWriter fw=新的FileWriter(路径,true); BufferedWriter bw=新的BufferedWriter(fw); 字符串myreadline=textf.getText(); 如果(ty==0){ if(fw==null)System.out.println(fw); 系统输出打印(ty); write(myreadline); }如果(ty==1){ int len=myreadline.length(); 对于(int i=0;i_Java_Filewriter_Numberformatexception - Fatal编程技术网

Java FileWriter抛出numberformatexception if(bsave==e.getSource()){ path=null; 试一试{ getpath(); }捕获(异常ee){ JOptionPane ss=新的JOptionPane(); showMessageDialog(这是“路径有问题……可能是中文名称……); } if(path==null)返回; 设置标题(路径); 试一试{ 文件=新文件(路径); 如果(!file.exists())file.createNewFile(); FileWriter fw=新的FileWriter(路径,true); BufferedWriter bw=新的BufferedWriter(fw); 字符串myreadline=textf.getText(); 如果(ty==0){ if(fw==null)System.out.println(fw); 系统输出打印(ty); write(myreadline); }如果(ty==1){ int len=myreadline.length(); 对于(int i=0;i

Java FileWriter抛出numberformatexception if(bsave==e.getSource()){ path=null; 试一试{ getpath(); }捕获(异常ee){ JOptionPane ss=新的JOptionPane(); showMessageDialog(这是“路径有问题……可能是中文名称……); } if(path==null)返回; 设置标题(路径); 试一试{ 文件=新文件(路径); 如果(!file.exists())file.createNewFile(); FileWriter fw=新的FileWriter(路径,true); BufferedWriter bw=新的BufferedWriter(fw); 字符串myreadline=textf.getText(); 如果(ty==0){ if(fw==null)System.out.println(fw); 系统输出打印(ty); write(myreadline); }如果(ty==1){ int len=myreadline.length(); 对于(int i=0;i,java,filewriter,numberformatexception,Java,Filewriter,Numberformatexception,,正如在上面的帖子中所评论的,FileWriter不会抛出NumberFormatException。请检查您的代码bw.write((char)chan.parseInt(myreadline.substring(i,i+7),2));。这里是从字符串解析为整数 最简单的调试方法是在try-catch(RuntimeException){}块中包围这些行,并仔细检查异常堆栈跟踪。FileWriter类(或此处显示的任何其他类)永远不会抛出NumberFormatException。这是你所有的

,正如在上面的帖子中所评论的,
FileWriter
不会抛出
NumberFormatException
。请检查您的代码
bw.write((char)chan.parseInt(myreadline.substring(i,i+7),2));
。这里是从字符串解析为整数


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

FileWriter类(或此处显示的任何其他类)永远不会抛出
NumberFormatException
。这是你所有的代码吗?你确定错误来自这部分代码吗?你能粘贴完整的代码和输入文件吗1)为了更快地获得更好的帮助,发布一个.2)将
catch(Exception e){..
格式的代码更改为
catch(Exception e){e.printStackTrace();//非常有用!。
粘贴相关的代码和异常堆栈跟踪。我错过了一个else。因此它转到第三部分,得到了。。。
                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());
        }           
    }