List of usage examples for java.io FileWriter write
public void write(int c) throws IOException
From source file:emailworkshop.EmailWorkshop.java
public static void exe(ArrayList<Checkin> lista, String emailAutentica, String senhaAutentica, String emailRecebe, boolean enviaEmailParticipante) { if (emailAutentica.isEmpty() || senhaAutentica.isEmpty()) { System.exit(0);//from w ww . jav a 2 s .co m } FileWriter fw = null; try { fw = new FileWriter("relatorioDeEnvio.txt"); } catch (IOException ex) { Logger.getLogger(EmailWorkshop.class.getName()).log(Level.SEVERE, null, ex); } int numCert = 2217; for (Checkin c : lista) { //if ("https://drive.google.com/open?id=0B0LxgGB17-B3aGVNMThsTXpWV0E".equals(c.getQrCode())) { gerarPDF(c.getNome(), numCert); try { if (!emailRecebe.isEmpty()) { enviaEmailComAnexo(emailAutentica, senhaAutentica, emailRecebe, c.getNome()); System.out.println("certificado de " + c.getNome() + " gerado!"); try { fw.write("certificado de " + c.getNome() + " gerado!\n"); } catch (IOException ex) { Logger.getLogger(EmailWorkshop.class.getName()).log(Level.SEVERE, null, ex); } } if (enviaEmailParticipante) { System.out.println("envia email para " + c.getNome()); enviaEmailComAnexo(emailAutentica, senhaAutentica, c.getEmail(), c.getNome()); } //avisoDeEnvio(c.getNome()); } catch (EmailException ex) { Logger.getLogger(EmailWorkshop.class.getName()).log(Level.SEVERE, null, ex); } //} numCert = numCert + 1; } try { fw.close(); } catch (IOException ex) { Logger.getLogger(EmailWorkshop.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:jeplus.TRNSYSWinTools.java
/** * Write a Job Done marker, typically a file named 'job.done!' in the given folder * * @param dir The folder in which the marker is written * @param marker The marker file name. The file contains a string "Job done!" * @return Marker is written successfully or not *///from ww w .jav a2 s. c o m public static boolean writeJobDoneMarker(String dir, String marker) { try { FileWriter fw = new FileWriter(dir + (dir.endsWith(File.separator) ? "" : File.separator) + marker); fw.write("Job done!"); fw.close(); return true; } catch (Exception ex) { logger.error("Error creating " + dir + (dir.endsWith(File.separator) ? "" : File.separator) + marker, ex); } return false; }
From source file:helpers.Methods.java
/** * This method will store the remaining links to the LOGS/Links.csv *//*from ww w . j av a 2 s. c o m*/ public static void makeLinksLogs() { FileWriter out = null; try { File inputDirectory = new File(Variables.inputFile); File outputFile = new File(checkDirectory(inputDirectory.getParent()) + File.separator + "Links.csv"); if (outputFile.getParentFile() != null) { outputFile.getParentFile().mkdirs(); } out = new FileWriter(outputFile); String tmp = ""; tmp = Variables.inputFileOutputFileName + "," + Variables.inputFileLinksColumnName + "\r\n"; out.write(tmp); //CSV Header for (WebDocument doc : getRemainingProfileLinks()) { doc.resetCounter(); tmp = doc.getOutputName() + ","; String url = doc.getNextUrl(); while (url != null) { tmp += url + Variables.inputFileLinksSeparator; url = doc.getNextUrl(); } //remove last separator //TODO Check the sustring works fine or not. //Error occured when all threads finished their work. tmp = tmp.substring(0, tmp.lastIndexOf(Variables.inputFileLinksSeparator)); out.write(tmp + "\r\n"); out.flush(); } out.close(); } catch (IOException ex) { Variables.logger.Log(Methods.class, Variables.LogType.Error, "Error in saving remaining links. Details:\r\n" + ex.getMessage()); } }
From source file:jeplus.TRNSYSWinTools.java
/** * Copy a file from one location to another * * @param from The source file to be copied * @param to The target file to write/*from ww w. jav a 2 s . c o m*/ * @return Successful or not */ public static boolean fileCopy(String from, String to) { boolean success = true; try { FileReader in = new FileReader(from); FileWriter out = new FileWriter(to); int c; while ((c = in.read()) != -1) { out.write(c); } in.close(); out.close(); } catch (Exception ee) { logger.error("Error copying " + from + " to " + to, ee); success = false; } return success; }
From source file:de.prozesskraft.pkraft.Manager.java
private static void exiterException(String pathToInstance, Exception e) { try {// ww w . j av a2 s . co m java.io.FileWriter writer = new FileWriter(pathToInstance + ".pkraft-manager.stacktrace", true); writer.write(new Timestamp(System.currentTimeMillis()).toString() + "\n"); writer.write(e.getMessage() + "\n"); writer.write(e.getStackTrace() + "\n"); writer.write("--------------" + "\n"); writer.close(); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } exit = true; System.exit(1); }
From source file:io.github.casnix.mcdropshop.util.configsys.Shops.java
public static boolean checkShopsFile() { File shopsFile = new File("./plugins/mcDropShop/Shops.json"); if (!shopsFile.exists()) return false; try {// w ww .j a va 2 s.c om String configTable = new String(Files.readAllBytes(Paths.get("./plugins/mcDropShop/Shops.json"))); JSONParser parser = new JSONParser(); Object obj = parser.parse(configTable); JSONObject jsonObj = (JSONObject) obj; String listVersion = (String) jsonObj.get("listVersion"); if (listVersion == null || !listVersion.equals("0.2.0")) { // Old version jsonObj.put("listVersion", "0.2.0"); // Update Shops.json FileWriter shopsJSON = new FileWriter("./plugins/mcDropShop/Shops.json"); shopsJSON.write(jsonObj.toJSONString()); shopsJSON.flush(); shopsJSON.close(); } return true; } catch (Exception e) { Bukkit.getLogger().severe("mcDropShop failed on setup check in Shops.json"); e.printStackTrace(); return false; } }
From source file:gov.nasa.jpl.memex.pooledtimeseries.PoT.java
private static void writeSimilarityToJSONFile(ArrayList<Path> files, double[][] similarities) { JSONObject root_json_obj = new JSONObject(); for (int i = 0; i < similarities.length; i++) { JSONObject fileJsonObj = new JSONObject(); for (int j = 0; j < similarities[0].length; j++) { fileJsonObj.put(files.get(j).getFileName(), similarities[i][j]); }//from ww w . ja v a2 s .c om root_json_obj.put(files.get(i).getFileName(), fileJsonObj); } try { outputFile = outputFile.substring(0, outputFile.lastIndexOf('.')) + ".json"; FileWriter file = new FileWriter(outputFile); file.write(root_json_obj.toJSONString()); file.flush(); file.close(); } catch (IOException e) { e.printStackTrace(); } }
From source file:edu.kit.dama.util.SystemUtils.java
/** * Generate the lock script for Unix systems. * * @return The full path to the lock script. * * @throws IOException If the generation fails. *//*from w w w .j a v a2s .c om*/ private static String generateLockScript() throws IOException { String scriptFile; FileWriter fout = null; try { scriptFile = FilenameUtils.concat(System.getProperty("java.io.tmpdir"), "lockFolder.sh"); fout = new FileWriter(scriptFile, false); StringBuilder b = new StringBuilder(); b.append("#!/bin/sh\n"); b.append("echo Changing owner of $1 to `whoami`\n"); b.append("chown `whoami` $1 -R\n"); b.append("echo Changing access of $1 to 700\n"); b.append("chmod 700 $1 -R\n"); LOGGER.debug("Writing script data to '{}'", scriptFile); fout.write(b.toString()); fout.flush(); } finally { if (fout != null) { try { fout.close(); } catch (IOException ioe) {//ignore } } } return scriptFile; }
From source file:com.bumptech.glide.disklrucache.DiskLruCacheTest.java
public static void writeFile(File file, String content) throws Exception { FileWriter writer = new FileWriter(file); writer.write(content); writer.close();//from www . j av a2s.c o m }
From source file:com.zimbra.qa.unittest.TestImap.java
private static Literal message(int size) throws IOException { File file = File.createTempFile("msg", null); file.deleteOnExit();//from w ww .j a va2 s . c o m FileWriter out = new FileWriter(file); try { out.write(simpleMessage("test message")); for (int i = 0; i < size; i++) { out.write('X'); if (i % 72 == 0) { out.write("\r\n"); } } } finally { out.close(); } return new Literal(file, true); }