List of usage examples for java.io FileWriter write
public void write(int c) throws IOException
From source file:com.atlassian.clover.eclipse.core.licensing.LicenseUtils.java
public static boolean writeLicenseTo(File licenseFile) throws IOException { String licenseText = CloverPlugin.getInstance().getInstallationSettings().getLicenseText(); if (licenseFile != null) { if (!licenseFile.exists()) { licenseFile.createNewFile(); }//from w w w . j a v a2s . c o m FileWriter writer = new FileWriter(licenseFile); writer.write(licenseText); writer.flush(); writer.close(); return true; } else { return false; } }
From source file:com.daphne.es.maintain.icon.web.controller.tmp.GenCssSql.java
private static void readClass() throws IOException { String fromFile = "C:\\Documents and Settings\\Administrator\\?\\a.txt"; String toFile = "C:\\Documents and Settings\\Administrator\\?\\b.sql"; String template = "insert into `maintain_icon` (`id`, `identity`, `css_class`, `type`) values(%1$d, '%2$s', '%2$s', 'css_class');;"; List<String> cssClassList = FileUtils.readLines(new File(fromFile)); List<String> hasReadList = Lists.newArrayList(); FileWriter writer = new FileWriter(toFile); for (int i = 0, l = cssClassList.size(); i < l; i++) { if (!hasReadList.contains(cssClassList.get(i))) { writer.write(String.format(template, i + 1, cssClassList.get(i).trim())); writer.write("\r\n"); hasReadList.add(cssClassList.get(i)); }/*from www. java2 s. co m*/ } writer.close(); }
From source file:com.grillecube.common.utils.JSONHelper.java
public static void writeJSONObjectToFile(File file, JSONObject json) { try {// w w w. ja va2 s .c om file.getParentFile().mkdirs(); FileWriter writer = new FileWriter(file); writer.write(json.toString()); writer.flush(); writer.close(); } catch (Exception e) { return; } }
From source file:Main.java
/** * write file/* w ww.ja va 2 s. c om*/ * * @param filePath * @param content * @param append * is append, if true, write to the end of file, else clear content of file and write into it * @return return true * @throws IOException * if an error occurs while operator FileWriter */ public static boolean writeFile(String filePath, String content, boolean append) { FileWriter fileWriter = null; try { fileWriter = new FileWriter(filePath, append); fileWriter.write(content); 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:au.org.ala.layers.util.BatchProducer.java
private static void writeToFile(String filename, String string) throws IOException { FileWriter fw = new FileWriter(filename); fw.write(string); fw.close();/*from www. ja v a 2 s . c o m*/ }
From source file:Util.java
public static boolean retreiveTextFileFromJar(String resourceName, String targetDirectory) throws Exception { boolean found = false; if (resourceName != null) { InputStream is = Util.class.getResourceAsStream(resourceName); if (is == null) logger.log(Level.WARNING, "The resource '" + resourceName + "' was not found."); BufferedReader br = new BufferedReader(new InputStreamReader(is)); String line;/*from w ww . j a v a 2 s . co m*/ String lineSep = System.getProperty("line.separator"); StringBuffer sb = new StringBuffer(); while ((line = br.readLine()) != null) { sb.append(line); sb.append(lineSep); } is.close(); if (sb != null) { if (sb.length() > 0) { FileWriter temp = new FileWriter(targetDirectory + File.separator + resourceName); temp.write(sb.toString()); temp.close(); found = true; } } } return (found); }
From source file:it.geosolutions.geostore.services.rest.auditing.AuditingTestsUtils.java
static void writeToFile(File file, String fileContent) { try {/*w w w . ja v a 2 s. c om*/ FileWriter writer = new FileWriter(file); writer.write(fileContent); writer.flush(); writer.close(); } catch (Exception exception) { throw new AuditingException(exception, "Error writing content to file '%s'.", file.getAbsolutePath()); } }
From source file:Main.java
/** * Serializes the given XML sub-tree to the given file. * /* w w w . j a v a 2 s .c om*/ * @param xml * The XML tree to serialize - must be a Document or Element. * @param file * The file to write to. If it already exists, its contents will * be overwritten; if it does not, it will be created. * @param printHeader * True if the standard XML document header should be added to * the top of the file. * @throws IOException * <ul> * <li>If there is an error creating, opening, or while writing * to the file.</li> * </ul> * @see #toString(Node, boolean) */ public static void toFile(final Node xml, final File file, final boolean printHeader) throws IOException { final String xmlString = toString(xml, printHeader); final FileWriter writer = new FileWriter(file); writer.write(xmlString); writer.close(); }
From source file:fll.web.WebTestUtils.java
private static void checkForServerError(final Page page) throws IOException { final com.gargoylesoftware.htmlunit.WebResponse response = page.getWebResponse(); final int code = response.getStatusCode(); final boolean error; if (code >= 400) { error = true;/*from www . j ava2s . c o m*/ } else { error = false; } if (error) { final String responseMessage = response.getStatusMessage(); final String text = getPageSource(page); final File output = File.createTempFile("server-error", ".html", new File("screenshots")); final FileWriter writer = new FileWriter(output); writer.write(text); writer.close(); Assert.fail("Error loading page: " + page.getUrl() + " code: " + code + " message: " + responseMessage + " Contents of error page written to: " + output.getAbsolutePath()); } }
From source file:mlbench.pagerank.PagerankMerge.java
private static void reduceDiffs(int local_diffs, int rank) { int diffs[] = { 0 }; int bs[] = { local_diffs }; try {/* w w w. j ava 2s. co m*/ MPI.COMM_WORLD.Reduce(bs, 0, diffs, 0, 1, MPI.INT, MPI.SUM, 0); MPI.COMM_WORLD.Barrier(); if (rank == 0) { LOG.info("Uncoveraged diffs:" + diffs[0]); FileWriter output = new FileWriter("var.tmp"); output.write(String.valueOf(diffs[0])); output.close(); JobConf conf = new JobConf(confPath); final FileSystem fs = FileSystem.get(conf); fs.copyFromLocalFile(true, new Path("./var.tmp"), new Path("var.tmp")); } } catch (MPIException | IOException e) { e.printStackTrace(); } }