List of usage examples for java.io BufferedWriter append
public Writer append(CharSequence csq) throws IOException
From source file:eu.cloud4soa.c4sgitservice.utils.Util.java
public static synchronized void appendToFile(String filename, String text) { FileWriter fWriter = null;// www . j a v a2 s . com BufferedWriter writer = null; try { fWriter = new FileWriter(filename, true); writer = new BufferedWriter(fWriter); writer.append(text); writer.newLine(); writer.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:jmc.util.UtlFbComents.java
public static void getURLComentarios(String url, Long numComents) throws JMCException { File f = null;/*from ww w .j a v a 2s . c om*/ try { Properties props = ConfigPropiedades.getProperties("props_config.properties"); CookieHandler.setDefault(new CookieManager(null, CookiePolicy.ACCEPT_ALL)); URL ur = new URL( "http://graph.facebook.com/comments?id=" + url + "&limit=" + numComents + "&filter=stream"); HttpURLConnection cn = (HttpURLConnection) ur.openConnection(); cn.setRequestProperty("user-agent", props.getProperty("navegador")); cn.setInstanceFollowRedirects(false); cn.setUseCaches(false); cn.connect(); BufferedReader br = new BufferedReader(new InputStreamReader(cn.getInputStream())); String dirTempHtml = props.getProperty("archive_json") + "/"; File fld = new File(dirTempHtml); boolean creado = fld.exists() ? true : fld.mkdir(); if (creado) { String archFile = "archivo.json"; String archivo = dirTempHtml + archFile; String linea = null; f = new File(archivo); BufferedWriter bw = new BufferedWriter(new FileWriter(f)); while ((linea = br.readLine()) != null) { bw.append(linea); } bw.close(); cn.disconnect(); List<Fbcoment> lfb = Convertidor.getFbcomentObjects(1l, archivo); // Fbcoment.actComents(idContenido, lfb); } else { cn.disconnect(); } } catch (IOException e) { throw new JMCException(e); } }
From source file:jmc.util.UtlFbComents.java
public static void getComentarios(Long idContenido, Long numComents) throws JMCException { File f = null;/*from www . ja v a 2 s . c o m*/ try { Properties props = ConfigPropiedades.getProperties("props_config.properties"); CookieHandler.setDefault(new CookieManager(null, CookiePolicy.ACCEPT_ALL)); URL ur = new URL("http://graph.facebook.com/comments?id=" + Contenido.getContenido("Where cont_id = '" + idContenido + "'").get(0).getEnlaceURL() + "&limit=" + numComents + "&filter=stream"); HttpURLConnection cn = (HttpURLConnection) ur.openConnection(); cn.setRequestProperty("user-agent", props.getProperty("navegador")); cn.setInstanceFollowRedirects(false); cn.setUseCaches(false); cn.connect(); BufferedReader br = new BufferedReader(new InputStreamReader(cn.getInputStream())); String dirTempHtml = props.getProperty("archive_json") + "/"; File fld = new File(dirTempHtml); boolean creado = fld.exists() ? true : fld.mkdir(); if (creado) { String archFile = idContenido + ".json"; String archivo = dirTempHtml + archFile; String linea = null; f = new File(archivo); BufferedWriter bw = new BufferedWriter(new FileWriter(f)); while ((linea = br.readLine()) != null) { bw.append(linea); } bw.close(); cn.disconnect(); List<Fbcoment> lfb = Convertidor.getFbcomentObjects(idContenido, archivo); Fbcoment.actComents(idContenido, lfb); } else { cn.disconnect(); } } catch (IOException e) { throw new JMCException(e); } }
From source file:it.geosolutions.tools.io.file.writer.Writer.java
/** * Open 'destination' file in append mode and append content of the * 'toAppend' file// w w w . j a va 2 s . com * * @param toAppend * @param destination * @throws IOException */ public static void appendFile(File toAppend, File destination) throws IOException { FileWriter fw = null; BufferedWriter bw = null; LineIterator it = null; try { fw = new FileWriter(destination, true); bw = new BufferedWriter(fw); it = FileUtils.lineIterator(toAppend); while (it.hasNext()) { bw.append(it.nextLine()); bw.newLine(); } bw.flush(); } finally { if (it != null) { it.close(); } if (bw != null) { IOUtils.closeQuietly(bw); } if (fw != null) { IOUtils.closeQuietly(fw); } } }
From source file:com.cemso.util.CheckDeviceStateExcuter.java
public static void checkWait() { if (log.isInfoEnabled()) { log.info("auto refresh is waiting..."); try {//from w ww. ja v a 2 s .co m File f = new File("C:/DLLfunctionsTest.txt"); FileWriter fw = new FileWriter(f, true); BufferedWriter bw = new BufferedWriter(fw); bw.newLine(); bw.append(new java.util.Date().toString() + ": auto refresh is waiting..."); bw.newLine(); bw.flush(); bw.close(); } catch (IOException e) { e.printStackTrace(); } } checkerHandle1.cancel(true); }
From source file:com.cemso.util.CheckDeviceStateExcuter.java
public static void checkStart() { if (log.isDebugEnabled()) { log.debug("CheckDeviceStateExcuter.checkStart()..."); }//from w w w .j a va 2 s . co m CheckRunner checker = new CheckDeviceStateExcuter().new CheckRunner(); Thread t = new Thread(checker, "checker"); checkerThread = t; final ScheduledFuture<?> checkerHandle = scheduler.scheduleAtFixedRate(t, 1, 2, TimeUnit.MINUTES); checkerHandle1 = checkerHandle; if (log.isInfoEnabled()) { log.info("auto refresh is started..."); try { File f = new File("C:/DLLfunctionsTest.txt"); FileWriter fw = new FileWriter(f, true); BufferedWriter bw = new BufferedWriter(fw); bw.newLine(); bw.append(new java.util.Date().toString() + ": auto refresh is started..."); bw.newLine(); bw.flush(); bw.close(); } catch (IOException e) { e.printStackTrace(); } } }
From source file:de.j4velin.mapsmeasure.Util.java
/** * Writes the given trace of points to the given file in CSV format, * separated by ";"//from w ww .j a v a2 s . c om * * @param f * the file to write to * @param trace * the trace to write * @throws IOException */ static void saveToFile(final File f, final Stack<LatLng> trace) throws IOException { if (!f.exists()) f.createNewFile(); BufferedWriter out = new BufferedWriter(new FileWriter(f)); LatLng current; for (int i = 0; i < trace.size(); i++) { current = trace.get(i); out.append(current.latitude + ";" + current.longitude + "\n"); } out.close(); }
From source file:Main.java
public static void writeLog(String log) { File file = new File("/sdcard/xh.log"); if (!file.exists()) { try {//from www . j av a 2 s. co m file.createNewFile(); } catch (IOException e) { // TODO Auto-generated catch block // e.printStackTrace(); } } BufferedWriter out = null; try { // Create file FileWriter fstream = new FileWriter("/sdcard/xh.log", true); out = new BufferedWriter(fstream); SimpleDateFormat sdf = new SimpleDateFormat("MM-dd HH:mm:ss "); String time = sdf.format(new Date(System.currentTimeMillis())); out.append(time); out.append(log); out.append("\r\n\r\n"); } catch (Exception e) {//Catch exception if any } finally { try { if (out != null) { out.close(); } } catch (IOException e) { } } }
From source file:com.normsstuff.maps4norm.Util.java
/** * Writes the given trace of points to the given file in CSV format, * separated by ";"/*from www . ja v a2 s . c o m*/ * * @param f the file to write to * @param trace the trace to write * @throws IOException */ static void saveToFile(final File f, final Stack<LatLng> trace) throws IOException { if (!f.exists()) f.createNewFile(); BufferedWriter out = new BufferedWriter(new FileWriter(f)); LatLng current; for (int i = 0; i < trace.size(); i++) { current = trace.get(i); out.append(String.valueOf(current.latitude)).append(";").append(String.valueOf(current.longitude)) .append("\n"); } out.close(); }
From source file:org.kuali.ole.gl.batch.BatchSortUtil.java
private static int sortToTempFiles(String inputFileName, File tempSortDir, Comparator<String> comparator) { BufferedReader inputFile;//from w w w . j av a 2 s. c om try { inputFile = new BufferedReader(new FileReader(inputFileName)); } catch (FileNotFoundException ex) { LOG.fatal("Unable to find input file: " + inputFileName, ex); throw new RuntimeException("Unable to find input file: " + inputFileName, ex); } try { String line = ""; ArrayList<String> batchLines = new ArrayList<String>(linesPerFile); int numFiles = 0; while (line != null) { // get 10k rows for (int i = 0; i < linesPerFile; i++) { line = inputFile.readLine(); if (line != null) { batchLines.add(line); } } // sort the rows // batchLines = mergeSort(batchLines, comparator); Collections.sort(batchLines, comparator); // write to disk BufferedWriter bw = new BufferedWriter(new FileWriter(new File(tempSortDir, "chunk_" + numFiles))); for (int i = 0; i < batchLines.size(); i++) { bw.append(batchLines.get(i)).append('\n'); } bw.close(); numFiles++; batchLines.clear(); // empty the array for the next pass } inputFile.close(); return numFiles; } catch (Exception ex) { LOG.fatal("Exception processing sort to temp files.", ex); throw new RuntimeException(ex); } }