List of usage examples for java.io FileWriter write
public void write(int c) throws IOException
From source file:de.pdark.dsmp.RequestHandler.java
public static void generateChecksum(File source, File f, String ext) { try {//from w w w .j a v a2 s.c o m String checksum = null; if ("md5".equals(ext)) { Md5Digester digester = new Md5Digester(); checksum = digester.calc(source); } else if ("sha1".equals(ext)) { Sha1Digester digester = new Sha1Digester(); checksum = digester.calc(source); } if (checksum != null) { FileWriter w = new FileWriter(f); w.write(checksum); w.write(SystemUtils.LINE_SEPARATOR); w.close(); } } catch (DigesterException e) { log.warn("Error creating " + ext.toUpperCase() + " checksum for " + source.getAbsolutePath(), e); } catch (IOException e) { log.warn("Error writing " + ext.toUpperCase() + " checksum for " + source.getAbsolutePath() + " to " + f.getAbsolutePath(), e); } }
From source file:com.ibm.watson.app.qaclassifier.tools.GenerateTrainingAndPopulationData.java
private static void writeGSON(String src, File output) throws IOException { FileWriter writer = null; try {//from w w w.j a v a 2s . c om writer = new FileWriter(output); writer.write(src); writer.flush(); } catch (IOException e) { e.printStackTrace(); } finally { try { writer.close(); } catch (IOException e) { e.printStackTrace(); } } }
From source file:com.axelor.apps.tool.file.FileTool.java
/** * Mthode permettant d'crire une ligne dans un fichier * @param destinationFolder/*w w w . j av a 2 s. co m*/ * Le chemin du fichier * @param fileName * Le nom du fichier * @param line * La ligne crire * @throws IOException */ public static void writer(String destinationFolder, String fileName, String line) throws IOException { System.setProperty("line.separator", "\r\n"); FileWriter writer = null; try { File file = create(destinationFolder, fileName); writer = new FileWriter(file); writer.write(line); } catch (IOException ex) { LOG.error(ex.getMessage()); } finally { if (writer != null) { writer.close(); } } }
From source file:com.serotonin.bacnet4j.util.sero.StreamUtils.java
public static void writeFile(File file, String content) throws IOException { FileWriter out = null; try {/*from w ww . j a v a 2s . c om*/ out = new FileWriter(file); out.write(content); } finally { if (out != null) out.close(); } }
From source file:lineage.LineageEngine.java
private static void writeTreesToTxtFile(PHYNetwork net, ArrayList<PHYTree> trees, ArrayList<String> sampleNames, Args args) {/*from ww w.j av a 2s . c om*/ String treeFileName = args.outputFileName; try { FileWriter fw = new FileWriter(treeFileName); fw.write("Nodes:\n" + net.getNodesWithMembersAsString() + "\n"); for (int i = 0; i < args.numSave; i++) { if (trees.size() > i) { fw.write("****Tree " + i + "****\n"); String edges = trees.get(i).toString(); fw.write(edges); fw.write("Error score: " + trees.get(i).getErrorScore() + "\n\n"); fw.write("Sample decomposition: \n"); String lineage = ""; for (int j = 0; j < sampleNames.size(); j++) { lineage += trees.get(i).getLineage(j, sampleNames.get(j)); lineage += "\n"; } fw.write(lineage); fw.write("\n"); } } fw.write("SNV info:\n" + net.getNodeMembersOnlyAsString() + "\n"); fw.close(); } catch (IOException e) { e.printStackTrace(); System.err.println("Failed to write to the file: " + treeFileName); System.exit(-1); } }
From source file:net.amigocraft.mpt.util.MiscUtil.java
/** * Writes the repository store to disk. This method is <strong>not</strong> thread-safe; the stores much be locked * by the caller./*w ww.j a va 2 s . c om*/ * @throws IOException if an exception occurs while writing data to the disk */ public static void writeRepositoryStore() throws IOException { File file = new File(Main.plugin.getDataFolder(), "repositories.json"); FileWriter writer = new FileWriter(file); // get a writer for the store file writer.write(JSONPrettyPrinter.toJSONString(Main.repoStore)); // write to disk writer.flush(); }
From source file:net.amigocraft.mpt.util.MiscUtil.java
/** * Writes the package store to disk. This method is <strong>not</strong> thread-safe; the stores much be locked * by the caller./*from www .j a v a2s . c o m*/ * @throws IOException if an exception occurs while writing data to the disk */ public static void writePackageStore() throws IOException { File file = new File(Main.plugin.getDataFolder(), "packages.json"); FileWriter writer = new FileWriter(file); // get a writer for the store file writer.write(JSONPrettyPrinter.toJSONString(Main.packageStore)); // write to disk writer.flush(); }
From source file:loadTest.loadTestLib.LUtil.java
public static void setUpResultFile() throws IOException { FileWriter writer = new FileWriter("loadTestResults.csv"); writer.write("NodeCount,FileCount,FileSize,ResultTime\n"); writer.flush();/*from w w w.j ava2 s. c om*/ writer.close(); }
From source file:Main.java
public static boolean writeFile(String filePath, List<String> contentList, boolean append) { if (contentList == null || contentList.size() < 1) { return false; }//from ww w . j a v a 2 s . c o m FileWriter fileWriter = null; try { makeDirs(filePath); fileWriter = new FileWriter(filePath, append); int i = 0; for (String line : contentList) { if (i++ > 0) { fileWriter.write("\r\n"); } fileWriter.write(line); } fileWriter.close(); return true; } catch (IOException e) { throw new RuntimeException("IOException occurred. ", e); } finally { if (fileWriter != null) { try { fileWriter.close(); } catch (IOException e) { throw new RuntimeException("IOException occurred. ", e); } } } }
From source file:com.abid_mujtaba.fetchheaders.models.Account.java
private static void createEmptyAccountsJsonFile(File file) { try {//from www. j a v a2s . c o m // We start by creating the JSON tree for an empty accounts.json file. JSONObject root = new JSONObject(); JSONArray accounts = new JSONArray(); root.put("accounts", accounts); // Save JSON to accounts.json FileWriter fw = new FileWriter(file); // Write root JSON object to file info.json fw.write(root.toString()); fw.flush(); fw.close(); } catch (JSONException e) { Log.e(Resources.LOGTAG, "Exception raised while manipulate JSON objects.", e); } catch (IOException e) { Log.e(Resources.LOGTAG, "Exception raised while saving content to json file.", e); } }