Java:把编写器变成String?

时间:2015-04-12 13:41:44

标签: java writer

我正在制作一个文本生成器,我编写了这个函数来构建输出文本文件。但是 - 我在应用程序中有两个选项 - 保存到文件和复制到剪贴板。

保存到文件工作正常,但genQC(false)表示它想生成文本并将其复制到剪贴板。我怎么能基本上把这个作家变成一个字符串? 我是java中编写者/文件处理的新手,所以我不确定这种情况。

 public void genQC(boolean save){
        if(save == true){
            try{
        File file = new File(fcs.getSetting("workingDir", "Not Set")+"\\"+smdFileName+".qc");
        JFileChooser f = new JFileChooser(fcs.getSetting("workingDir", "C:"));
        f.setSelectedFile(file);
        f.showSaveDialog(null);
        String selectedPath = String.valueOf(f.getSelectedFile());
        System.out.println(selectedPath);


        PrintWriter writer = new PrintWriter(selectedPath, "UTF-8");
        writer.println("$modelname \""+modelFinalPath+modelFinalName+".mdl\"");
        writer.println("$scale "+ (scale / 10));
        if(staticprop == true){
            writer.println("$staticprop");
        }
        writer.println("$bodygroup \"Body\"");
        writer.println("{");
        writer.println("\tstudio \""+refPath+"\"");
        writer.println("}");
        writer.println("$cdmaterials \""+materialsFinalPath+"\"");
        writer.println("$surfaceprop \""+surfaceProp+"\"");
        writer.println("$sequence idle \""+refPath+"\" loop fps 15");
        if(nocollision == false){
            if(defcollision == true){
                writer.println("$collisionmodel \""+refPath+"\"");
            }
            else if(defcollision == false){
                writer.println("$collisionmodel \""+colPath+"\"");
            }
            writer.println("{");
            if(automass == false){
            writer.println("\t$mass "+mass);
            }
            else{
            writer.println("\t$automass");    
            }
            writer.println("\t$concave");
            writer.println("}");

        }
        else{
            //Nothing
        }
        writer.close();
            }
            catch(Exception e){
                e.printStackTrace();
            }
        }
        else if(save == false){
            StringSelection stringSelection = new StringSelection ("ehh");
            Clipboard clpbrd = Toolkit.getDefaultToolkit ().getSystemClipboard ();
            clpbrd.setContents (stringSelection, null);
        }




    }

我假设我需要阻止或其他什么?

0 个答案:

没有答案