JAVA中FileHelper的一个用法

来源:互联网 发布:手机智能对话软件 编辑:程序博客网 时间:2024/04/28 22:25

 public boolean writeXML(String content, String filename)
    {  
        String savepath;
        FileOutputStream fout;
//        log.info("content:"+content+" filename:"+filename+" writeDir:"+writeDir);
        savepath = (new StringBuilder(String.valueOf(writeDir))).append(File.separatorChar).append(filename).toString();
        fout = null;
        if(content == null)
            return false;
        File file = new File(writeDir);
        try
        {
         if(!file.exists()){
          file.mkdirs();
         }
            fout = new FileOutputStream(savepath);
            byte buffer[] = content.getBytes();
            fout.write(buffer);
           // break MISSING_BLOCK_LABEL_111;
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
        if(fout != null)
            try
            {
                fout.close();
            }
            catch(IOException e)
            {
                return false;
            }
       // return false;
       // Exception exception;
       // exception;
        if(fout != null)
            try
            {
                fout.close();
            }
            catch(IOException e)
            {
                return false;
            }
        //throw exception;
        if(fout != null)
            try
            {
                fout.close();
            }
            catch(IOException e)
            {
                return false;
            }
        return true;
    }

原创粉丝点击