Java Code Examples for java.io.FileWriter.write()

The following are Jave code examples for showing how to use write() of the java.io.FileWriter class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: etomica   File: PotentialCalculationMappedRdf.java   View Source Code Vote up 7 votes
public static void main (String[] args) throws IOException {
Simulation sim = new Simulation(Space3D.getInstance());
Box box = new Box(sim.getSpace());

PotentialCalculationMappedRdf pc = new PotentialCalculationMappedRdf(sim.getSpace(),box, 1000000, null);
P2LennardJones potential = new P2LennardJones(sim.getSpace());
P2SoftSphericalTruncated p2Truncated = new P2SoftSphericalTruncated(sim.getSpace(), potential, 4);

pc.setVolume(99999.99999999997);
pc.setTemperature(2, p2Truncated);
double rc = p2Truncated.getRange();
double x0 = rc;

FileWriter fw = new FileWriter("vu.dat");
for (int i=10; i<45; i++) {
    double r = i*0.1;
    if (r>=4) r = 3.99999999;
               System.out.println(r+" "+pc.calcXu(r, p2Truncated.u(r*r))+" ");
               fw.write(r+" "+pc.calcXu(r, p2Truncated.u(r*r))+"\n");
           }

fw.close();

  }
 
Example 2
Project: featurea   File: TexturePackerManager.java   View Source Code Vote up 6 votes
private void writePackFile(File outputDir, Array<Page> pages, String packFileName) throws IOException {
    File packFile = new File(outputDir, packFileName);
    FileWriter writer = new FileWriter(packFile);
    for (Page page : pages) {
        writer.write("\n"); // todo avoid this
        writer.write(page.imageName + "\n");
        writer.write("size: " + page.canvasWidth + "," + page.canvasHeight + "\n");
        writer.write("format: RGBA8888\n");
        writer.write("filter: Nearest,Nearest\n");
        writer.write("repeat: none\n");
        for (Rect rect : page.outputRects) {
            writeRect(writer, page, rect);
            for (Alias alias : rect.aliases) {
                Rect aliasRect = new Rect();
                aliasRect.set(rect);
                alias.apply(aliasRect);
                writeRect(writer, page, aliasRect);
            }
        }
    }
    writer.close();
}
 
Example 3
Project: Sunrin2017   File: Exam2.java   View Source Code Vote up 6 votes
public static void main(String[] args) throws IOException {
	String fileName = "data.txt";
	DataReader in = new DataReader(new FileReader(fileName));
	FileWriter fw = new FileWriter("data-output.txt");

	ArrayList<Data> dataList = new ArrayList<>();
	Data data = new Data();
	
	data.printFields();

	while ((data = in.readData()) != null) {
		dataList.add(data);
		fw.write(data.toString() + System.lineSeparator());
		data.print();
	}
	
	in.close();
	fw.close();
}
 
Example 4
Project: lams   File: JspC.java   View Source Code Vote up 6 votes
protected void initWebXml() {
    try {
        if (webxmlLevel >= INC_WEBXML) {
            File fmapings = new File(webxmlFile);
            mapout = new FileWriter(fmapings);
            servletout = new CharArrayWriter();
            mappingout = new CharArrayWriter();
        } else {
            mapout = null;
            servletout = null;
            mappingout = null;
        }
        if (webxmlLevel >= ALL_WEBXML) {
            mapout.write(Localizer.getMessage("jspc.webxml.header"));
            mapout.flush();
        } else if ((webxmlLevel>= INC_WEBXML) && !addWebXmlMappings) {
            mapout.write(Localizer.getMessage("jspc.webinc.header"));
            mapout.flush();
        }
    } catch (IOException ioe) {
        mapout = null;
        servletout = null;
        mappingout = null;
    }
}
 
Example 5
Project: dashboard1b   File: WreportP.java   View Source Code Vote up 5 votes
@Override
public void log(String datos) {		
	File file = new File("logP.txt");

	try {				

		FileWriter fW = new FileWriter(file, true);
		fW.write(new Date()+" - "+datos+"\n");
		fW.close();

	} catch (IOException e) {
		e.printStackTrace();
	}

}
 
Example 6
Project: TruenoNPC   File: TruenoNPC_v1_11_r1.java   View Source Code Vote up 5 votes
private void cacheSkin(SkinData skindata){
    JsonObject jsonFile = getChacheFile(plugin);
    JsonArray newskindata = new JsonArray();
    if(jsonFile!=null){
        JsonArray oldskindata = jsonFile.getAsJsonArray("skindata");
        Iterator it = oldskindata.iterator();
        while(it.hasNext()){
            JsonElement element = (JsonElement) it.next();
            if(element.getAsJsonObject().get("id").getAsInt()==this.npcid){
                // element.getAsJsonObject().remove("value");
                //element.getAsJsonObject().remove("signature");
                //element.getAsJsonObject().addProperty("value", skindata.getValue());
                //element.getAsJsonObject().addProperty("signature", skindata.getSignature());
            }else {
                newskindata.add(element);
            }
        }
    }
    JsonObject skin = new JsonObject();
    skin.addProperty("id", this.npcid);
    skin.addProperty("value", skindata.getValue());
    skin.addProperty("signature", skindata.getSignature());
    newskindata.add(skin);

    JsonObject obj = new JsonObject();
    obj.add("skindata", newskindata);
    try {
        plugin.getDataFolder().mkdir();
        File file = new File(plugin.getDataFolder().getPath()+"/truenonpcdata.json");
        file.createNewFile();
        FileWriter writer = new FileWriter(file);
        writer.write(obj.toString());
        writer.close();

    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example 7
Project: parabuild-ci   File: SSTestWindowsBuildScriptRunner.java   View Source Code Vote up 5 votes
public void test_executeBuildRetunsZeroResult() throws Exception {
  if (!agent.isWindows()) return;
  final FileWriter fw = new FileWriter(script);
  fw.write("rem Test script file \n");
  fw.write("echo test successful\n");
  IoUtils.closeHard(fw);
  assertEquals(0, scriptRunner.executeBuildScript(script.getAbsolutePath()));
}
 
Example 8
Project: personium-core   File: LogTest.java   View Source Code Vote up 5 votes
/**
 * 引数に存在する圧縮ファイルパスを渡した場合_レスポンスボディにStreamingOutputオブジェクトが入ったSC_OKレスポンスが返る.
 * ※ レスポンスに返されるログの内容は、本Unitテストでは検査不可なため、別途検証する。
 */
@Test
public void コレクション名がarchiveで引数に圧縮されていないファイルパスを渡した場合_500エラーが返却されること() {
    TestLogResource logResource = new TestLogResource();

    try {
        Method method = LogResource.class.getDeclaredMethod("getLog", new Class[] {String.class, String.class });
        method.setAccessible(true);

        File file = File.createTempFile("TestFile", ".log.zip");
        file.deleteOnExit();

        final String logContent = "a,b,c\n" + "x,y,z\n";
        FileWriter writer = new FileWriter(file);
        try {
            writer.write(logContent);
        } finally {
            writer.close();
        }

        String filename = file.getAbsolutePath();
        String paramFileName = filename.substring(0, filename.length() - ".zip".length());

        // ログ取得実行
        method.invoke(logResource, new Object[] {"archive", paramFileName });
        fail();
    } catch (Exception e) {
        Throwable t = e.getCause();
        assertEquals(PersoniumCoreException.Event.ARCHIVE_FILE_CANNOT_OPEN.getMessage(), t.getMessage());
    }
}
 
Example 9
Project: BaseClient   File: CrashReport.java   View Source Code Vote up 5 votes
/**
 * Saves this CrashReport to the given file and returns a value indicating whether we were successful at doing so.
 */
public boolean saveToFile(File toFile)
{
    if (this.crashReportFile != null)
    {
        return false;
    }
    else
    {
        if (toFile.getParentFile() != null)
        {
            toFile.getParentFile().mkdirs();
        }

        try
        {
            FileWriter filewriter = new FileWriter(toFile);
            filewriter.write(this.getCompleteReport());
            filewriter.close();
            this.crashReportFile = toFile;
            return true;
        }
        catch (Throwable throwable)
        {
            logger.error("Could not save crash report to " + toFile, throwable);
            return false;
        }
    }
}
 
Example 10
Project: SnapDup   File: GenerateScriptDialog.java   View Source Code Vote up 5 votes
@FXML
private void btnSaveAction()
{
	FileChooser fileChooser = new FileChooser();
	File file = fileChooser.showSaveDialog(btnSave.getScene().getWindow());
	
	if(file == null)
		return;
	
	try
	{
		FileWriter stream = new FileWriter(file);
		
		try
		{
			file.createNewFile();
			stream.write(txtArea.getText());
		}
		finally
		{
			stream.close();
		}
	}
	catch (IOException e)
	{
		e.printStackTrace();
	}
}
 
Example 11
Project: Java-APIs   File: DirectoryClassifier.java   View Source Code Vote up 5 votes
public void parseFile(File inputFile, File outputFile) throws ClassificationException, IOException {
	logger.debug("Treating file: '" + inputFile + "'");
	
	
	Map<String, Collection<ClassificationScore>> classificationScores = classificationClient.getClassifiedDocument(inputFile, null).getAllClassifications();

	FileWriter fileWriter = new FileWriter(outputFile);
	for (String rulebaseClass: classificationScores.keySet()) {
		fileWriter.write(rulebaseClass + "\r\n");
		for (ClassificationScore classificationScore: classificationScores.get(rulebaseClass)) {
			fileWriter.write(classificationScore.getName() + ":" + classificationScore.getScore() + "\r\n");
		}
	}
	fileWriter.close();
}
 
Example 12
Project: wherehowsX   File: HBaseMetaExtractor.java   View Source Code Vote up 5 votes
private void initWriters() throws IOException {

        schemaFileWriter = new FileWriter(this.hbaseMetaFile);
        sampleFileWriter = new FileWriter(this.hbaseSampleFile);
        //if file exist and clear its content
        schemaFileWriter.write("");
        sampleFileWriter.write("");
    }
 
Example 13
Project: tg-qq-trans   File: CreateConfigs.java   View Source Code Vote up 5 votes
public static void createConfigs(File configFile)
{
	
	ConfigData configData = new ConfigData();
	configData.coolqDir = "./coolq";
	configData.qqBotPort = 11235;
	configData.qqBotNumber = "10000";
	configData.telegramBotToken = "";
	GroupsPairs sample = new GroupsPairs();
	sample.qqGroup = 10000;
	sample.telegramGroup = -1;
	configData.groupsPairs = new ArrayList<GroupsPairs>();
	configData.groupsPairs.add(sample);
	configData.proxyConfig = new ProxyConfig();
	configData.proxyConfig.enableProxy = false;
	configData.proxyConfig.proxyType = "SOCKS";
	configData.proxyConfig.proxyHost = "127.0.0.1";
	configData.proxyConfig.proxyPort = 1080;
	configData.enabledPlugins = new ArrayList<String>();
	configData.enabledPlugins.add("plugins.Transport");
	
	Gson gson = new GsonBuilder().setPrettyPrinting().create();
	String JSONString = gson.toJson(configData);
	
	try
	{
		FileWriter out = new FileWriter(configFile.toString());
		out.write(JSONString);
		out.close();
	}
	catch(IOException e)
	{
		e.printStackTrace();
	}
}
 
Example 14
Project: DIA-Umpire-Maven   File: LCMSID.java   View Source Code Vote up 5 votes
private void ExportPepPSMCSV(String folder) throws IOException {
    if (folder == null | "".equals(folder)) {
        folder = FilenameUtils.getFullPath(mzXMLFileName);
    }
    Logger.getRootLogger().info("Writing PSM result to file:" + folder + FilenameUtils.getBaseName(mzXMLFileName) + "_PSMs.csv...");
    FileWriter writer = new FileWriter(folder + FilenameUtils.getBaseName(mzXMLFileName) + "_PSMs.csv");
    writer.write("SpecID,Sequence,ModSeq,TPPModSeq,Modification,Charge,mz,NeutralPepMass,ObservedMass,RT,AdjustedRT,Rank,ScanNo,PreAA,NextAA,MissedCleavage,ExpectValue,MassError,Prob,Rawname,ParentPepIndex,MS1Quant\n");
    for (PepIonID pepion : PepIonList.values()) {
        for (PSM psm : pepion.GetPSMList()) {
            writer.write(psm.SpecNumber + "," + psm.Sequence + "," + psm.ModSeq + "," + psm.TPPModSeq + "," + psm.GetModificationString() + "," + psm.Charge + "," + psm.ObserPrecursorMz() + "," + psm.NeutralPepMass + "," + psm.ObserPrecursorMass + "," + psm.RetentionTime + "," + psm.NeighborMaxRetentionTime + "," + psm.Rank + "," + psm.ScanNo + "," + psm.PreAA + "," + psm.NextAA + "," + psm.MissedCleavage + "," + psm.expect + "," + psm.MassError + "," + psm.Probability + "," + psm.RawDataName + "," + pepion.Index + "," + pepion.GetMS1() + "\n");
        }
    }
    writer.close();
}
 
Example 15
Project: ObsidianSuite   File: Main.java   View Source Code Vote up 5 votes
private static void saveFile(File file, List<String> lines) throws IOException
{
    FileWriter writer = new FileWriter(file);
    for (String str : lines)
    {
        writer.write(str);
        writer.write("\n");
    }
    writer.close();
}
 
Example 16
Project: https-github.com-apache-zookeeper   File: ZooKeeperServerMainTest.java   View Source Code Vote up 5 votes
public MainThread(int clientPort, boolean preCreateDirs, File tmpDir, String configs)
        throws IOException {
    super("Standalone server with clientPort:" + clientPort);
    this.tmpDir = tmpDir;
    confFile = new File(tmpDir, "zoo.cfg");

    FileWriter fwriter = new FileWriter(confFile);
    fwriter.write("tickTime=2000\n");
    fwriter.write("initLimit=10\n");
    fwriter.write("syncLimit=5\n");
    if(configs != null){
        fwriter.write(configs);
    }

    dataDir = new File(this.tmpDir, "data");
    logDir = new File(dataDir.toString() + "_txnlog");
    if (preCreateDirs) {
        if (!dataDir.mkdir()) {
            throw new IOException("unable to mkdir " + dataDir);
        }
        if (!logDir.mkdir()) {
            throw new IOException("unable to mkdir " + logDir);
        }
        ClientBase.createInitializeFile(logDir);
    }
    
    String normalizedDataDir = PathUtils.normalizeFileSystemPath(dataDir.toString());
    String normalizedLogDir = PathUtils.normalizeFileSystemPath(logDir.toString());
    fwriter.write("dataDir=" + normalizedDataDir + "\n");
    fwriter.write("dataLogDir=" + normalizedLogDir + "\n");
    fwriter.write("clientPort=" + clientPort + "\n");
    fwriter.flush();
    fwriter.close();

    main = new TestZKSMain();
}
 
Example 17
Project: sepatools   File: EngineProperties.java   View Source Code Vote up 4 votes
private void storeProperties(String propertiesFile) throws IOException {
	FileWriter out = new FileWriter(propertiesFile);
	out.write(parameters.toString());
	out.close();
}
 
Example 18
Project: hadoop   File: TestHardLink.java   View Source Code Vote up 4 votes
private void makeNonEmptyFile(File file, String contents) 
throws IOException {
  FileWriter fw = new FileWriter(file);
  fw.write(contents);
  fw.close();
}
 
Example 19
Project: DIA-Umpire-Maven   File: LCMSPeakBase.java   View Source Code Vote up 4 votes
public void ExportPeakClusterResultCSV() throws IOException {

        Logger.getRootLogger().info("Writing PeakCluster CSV:" + FilenameUtils.getFullPath(ScanCollectionName) + FilenameUtils.getBaseName(ScanCollectionName) + "_PeakCluster.csv...");
        FileWriter writer = new FileWriter(FilenameUtils.getFullPath(ScanCollectionName) + FilenameUtils.getBaseName(ScanCollectionName) + "_PeakCluster.csv");

        String mzstring = "";
        String Idxstring = "";
        String CorrString = "";
        String SNRString = "";
        String PeakheightString = "";
        String PeakheightRTString = "";
        String PeakAreaString = "";
        String IdentifiedString = "0";

        for (int i = 0; i < MaxNoPeakCluster; i++) {
            mzstring += ",mz" + (i + 1);
            Idxstring += ",PeakIdx" + (i + 1);
            if (i > 0) {
                CorrString += ",Corr" + (i + 1);
            }
            SNRString += ",SNR" + (i + 1);
            PeakheightString += ",PeakHeight" + (i + 1);
            PeakheightRTString += ",PeakHeightRT" + (i + 1);
            PeakAreaString += ",PeakArea" + (i + 1);
        }

        writer.write("Cluster_Index,StartRT,EndRT,StartScan,EndScan,Identified,Charge" + mzstring + Idxstring + CorrString + SNRString + PeakheightString + PeakheightRTString + PeakAreaString + ",IsoMapProb,ConflictCorr,LeftInt,RightInt,NoRidges,MS1Score,MS1Prob,MS1LProb\n");

        for (PeakCluster cluster : PeakClusters) {
            IdentifiedString = "0";
            if (cluster.Identified) {
                IdentifiedString = "1";
            }

            String statementString = cluster.Index + "," + cluster.startRT + "," + cluster.endRT + "," + cluster.StartScan + "," + cluster.EndScan + "," + IdentifiedString + "," + cluster.Charge + ",";

            mzstring = "";
            Idxstring = "";
            CorrString = "";
            SNRString = "";
            PeakheightString = "";
            PeakheightRTString = "";
            PeakAreaString = "";

            for (int i = 0; i < MaxNoPeakCluster; i++) {
                mzstring += cluster.mz[i] + ",";
                Idxstring += cluster.IsoPeakIndex[i] + ",";
                if (i > 0) {
                    CorrString += cluster.Corrs[i - 1] + ",";
                }
                SNRString += cluster.GetSNR(i) + ",";
                PeakheightString += cluster.PeakHeight[i] + ",";
                PeakheightRTString += cluster.PeakHeightRT[i] + ",";
                PeakAreaString += cluster.PeakArea[i] + ",";
            }
            statementString += mzstring + Idxstring + CorrString + SNRString + PeakheightString + PeakheightRTString + PeakAreaString + cluster.IsoMapProb + "," + cluster.GetConflictCorr() + "," + cluster.LeftInt + "," + cluster.RightInt + "," + cluster.NoRidges + "," + cluster.MS1Score + "," + cluster.MS1ScoreProbability + "," + cluster.MS1ScoreLocalProb + "\n";
            writer.write(statementString);
        }
        writer.close();
        //System.out.print("Finished multithreading\n");
    }
 
Example 20
Project: DocIT   File: JFragmentLocator.java   View Source Code Vote up 4 votes
private static void writeOutput(String fileName, String output) throws IOException {
    FileWriter writer = new FileWriter(new File(fileName));
    writer.write(output);
    writer.write('\n');
    writer.close();
}