List of usage examples for java.io BufferedWriter close
@SuppressWarnings("try") public void close() throws IOException
From source file:files.FileUtils.java
public static boolean WriteDatFile(String pathFileText, String fileContent) { try {//w w w . ja v a 2 s . co m File file = new File(pathFileText); //if file doesnt exists, then create it if (!file.exists()) { file.createNewFile(); } //Collecting Data if (!IsNullOrEmpty(fileContent)) { //true = append file FileWriter fileWritter = new FileWriter(file.getPath(), true); BufferedWriter bufferWritter = new BufferedWriter(fileWritter); bufferWritter.write(fileContent); bufferWritter.close(); return true; } } catch (Exception ex) { return false; } return false; }
From source file:com.company.et.service.JsonService.java
/** * * @param json String what we write to file *///from www. j ava 2 s .co m public static void writeToFile(String json) { try { File file = new File(getFilename()); if (!file.exists()) { file.createNewFile(); } FileWriter fw = new FileWriter(file.getAbsoluteFile()); BufferedWriter bw = new BufferedWriter(fw); bw.write(json); bw.close(); // @TODO: add LOG message } catch (IOException e) { e.printStackTrace(); // @TODO: add LOG message } }
From source file:com.ibm.bi.dml.runtime.io.IOUtilFunctions.java
/** * /*w ww . j av a2s .c o m*/ * @param br */ public static void closeSilently(BufferedWriter bw) { try { if (bw != null) bw.close(); } catch (Exception ex) { LOG.error("Failed to buffered writer.", ex); } }
From source file:Main.java
/** * Writes the current app logcat to a file. * * @param filename The filename to save it as * @throws IOException//from w w w .jav a2s.c o m */ public static void writeLogcat(String filename) throws IOException { String[] args = { "logcat", "-v", "time", "-d" }; Process process = Runtime.getRuntime().exec(args); InputStreamReader input = new InputStreamReader(process.getInputStream()); OutputStreamWriter output = new OutputStreamWriter(new FileOutputStream(filename)); BufferedReader br = new BufferedReader(input); BufferedWriter bw = new BufferedWriter(output); String line; while ((line = br.readLine()) != null) { bw.write(line); bw.newLine(); } bw.close(); output.close(); br.close(); input.close(); }
From source file:amazonechoapi.AmazonEchoApi.java
private static void addItemId(String itemId) throws IOException { File file = new File("Items.txt"); try {/*from w w w. j a v a 2 s.co m*/ if (!file.exists()) { file.createNewFile(); } FileWriter fileWritter = new FileWriter(file.getName(), true); BufferedWriter bufferWritter = new BufferedWriter(fileWritter); bufferWritter.write(itemId + "\n"); bufferWritter.close(); } catch (Exception e) { } }
From source file:com.aistor.generate.Generate.java
/** * //from w ww .j a v a 2s. c o m * @param content * @param filePath */ public static void writeFile(String content, String filePath) { try { if (FileUtils.createFile(filePath)) { FileWriter fileWriter = new FileWriter(filePath, true); BufferedWriter bufferedWriter = new BufferedWriter(fileWriter); bufferedWriter.write(content); bufferedWriter.close(); fileWriter.close(); } else { logger.info("??"); } } catch (Exception e) { e.printStackTrace(); } }
From source file:com.lunix.cheata.utils.file.FileManager.java
public static void WriteFile(String fileName, String string) { try {// w w w.j a v a 2 s . c o m BufferedWriter writer = new BufferedWriter( new FileWriter(new File(getDir().getAbsolutePath(), fileName))); writer.write(string); writer.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.devdungeon.httpexamples.DownloadFile.java
private static void download(String url, String filepath) { HttpClient client = new DefaultHttpClient(); HttpParams params = client.getParams(); HttpConnectionParams.setConnectionTimeout(params, 1000 * 5); HttpConnectionParams.setSoTimeout(params, 1000 * 5); HttpGet request = new HttpGet(url); HttpResponse response = null;/*from w ww . j a v a 2 s .co m*/ try { response = client.execute(request); } catch (IOException ex) { Logger.getLogger(HttpGetExample.class.getName()).log(Level.SEVERE, null, ex); } BufferedReader rd; String line = null; try { rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); FileWriter fileWriter = new FileWriter(filepath); BufferedWriter bufferedWriter = new BufferedWriter(fileWriter); while ((line = rd.readLine()) != null) { bufferedWriter.write(line); bufferedWriter.newLine(); } bufferedWriter.close(); } catch (IOException ex) { Logger.getLogger(HttpGetExample.class.getName()).log(Level.SEVERE, null, ex); } catch (UnsupportedOperationException ex) { Logger.getLogger(HttpGetExample.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.pseudosudostudios.jdd.utils.ScoreSaves.java
private static void writeFile(Context c, List<Entry> entries) { Collections.sort(entries);/* ww w. j a va 2 s. c o m*/ File file = new File(c.getFilesDir(), fileName); try { file.createNewFile(); JSONArray array = new JSONArray(); for (Entry e : entries) array.put(makeJSONObject(e)); BufferedWriter writer = new BufferedWriter(new FileWriter(file)); writer.write(array.toString()); writer.close(); } catch (IOException e) { e.printStackTrace(); return; } }
From source file:jt56.comm.code.util.CommonPageParser.java
public static void WriterPage(VelocityContext context, String templateName, String fileDirPath, String targetFile) {/* w ww .j a v a 2s. com*/ try { File file = new File(fileDirPath + targetFile); if (!(file.exists())) { new File(file.getParent()).mkdirs(); } else if (isReplace) { log.info("?:" + file.getAbsolutePath()); } Template template = ve.getTemplate(templateName, "UTF-8"); FileOutputStream fos = new FileOutputStream(file); BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(fos, "UTF-8")); template.merge(context, writer); writer.flush(); writer.close(); fos.close(); log.info("?" + file.getAbsolutePath()); } catch (Exception e) { log.error(e); } }