List of usage examples for java.io BufferedWriter BufferedWriter
public BufferedWriter(Writer out)
From source file:FileUtils.java
public static void makeFile(String Path, String content) { try {//from w w w . ja va 2 s .c o m // Create file FileWriter fstream = new FileWriter(Path); BufferedWriter bf = new BufferedWriter(fstream); bf.write(content); // Close the output stream bf.close(); } catch (Exception e) {// Catch exception if any System.err.println("Error: " + e.getMessage()); } }
From source file:com.reversemind.glia.test.go3.java
public static void save(String fileName, String string) throws Exception { BufferedWriter bw = new BufferedWriter(new FileWriter(new File(fileName))); bw.write(string + "\n"); bw.flush();/*w w w .jav a2s. c om*/ bw.close(); }
From source file:it.sardegnaricerche.voiceid.sr.Voiceid.java
public static void main(String[] args) { logger.info("Voiceid main method"); logger.info("First argument: '" + args[0] + "'"); long startTime = System.currentTimeMillis(); Voiceid voiceid = null;// w w w. j a v a 2 s .co m GMMVoiceDB db = null; try { db = new GMMVoiceDB(args[1], new UBMModel(args[0])); File f = new File(args[2]); voiceid = new Voiceid(db, f, new LIUMStandardDiarizator()); voiceid.extractClusters(); voiceid.matchClusters(); // voiceid.toWav(); // voiceid.printClusters(); JSONObject obj = voiceid.toJson(); for (VCluster c : voiceid.getClusters()) { logger.info("" + c.getSample().getResource().getAbsolutePath()); } // FileWriter fstream = new // FileWriter(f.getAbsolutePath().replaceFirst("[.][^.]+$", "") + // ".json"); String filename = Utils.getBasename(f) + ".json"; FileWriter fstream = new FileWriter(filename); BufferedWriter out = new BufferedWriter(fstream); out.write(obj.toString()); // Close the output stream out.close(); // voiceid.makeAllModels(); } catch (IOException e) { logger.severe(e.getMessage()); } catch (Exception ex) { logger.severe(ex.getMessage()); } long endTime = System.currentTimeMillis(); long duration = endTime - startTime; logger.info("Exit (" + ((float) duration / 1000) + " s)"); // logger.info("Max Threads: " + (int) db.maxThreads); }
From source file:Main.java
public static <T extends Object> String marshalAsString(Class clz, T marshalObj) throws JAXBException { JAXBContext context = JAXBContext.newInstance(clz); Marshaller marshaller = context.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); StringWriter writer = new StringWriter(); marshaller.marshal(marshalObj, new BufferedWriter(writer)); return writer.toString(); }
From source file:Main.java
public static void write(String text, File dst) throws IOException { BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(dst)); bufferedWriter.write(text);/*from ww w . j a va 2 s . c o m*/ bufferedWriter.flush(); bufferedWriter.close(); }
From source file:Main.java
/** * Print out the spike trains so it can be analyzed by plotting software * @param file/* www . j a v a 2s . c om*/ * @param array */ public static void print(File file, double[] array) { FileWriter fstream = null; BufferedWriter out = null; try { fstream = new FileWriter(file); out = new BufferedWriter(fstream); for (int i = 0; i < array.length; i++) { out.write(array[i] + "\t"); } } catch (IOException e) { e.printStackTrace(); } finally { if (out != null) { try { out.close(); } catch (IOException e) { e.printStackTrace(); } } if (fstream != null) { try { fstream.close(); } catch (IOException e) { e.printStackTrace(); } } } }
From source file:Main.java
public static boolean write(String filename, Document document, boolean addDocType) { try {//from ww w . j av a 2 s .c om TransformerFactory tf = TransformerFactory.newInstance(); tf.setAttribute("indent-number", new Integer(4)); Transformer transformer = tf.newTransformer(); DOMSource source = new DOMSource(document); if (addDocType) { transformer.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC, "-//Sun Microsystems, Inc.//DTD Facelet Taglib 1.0//EN"); transformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, "http://java.sun.com/dtd/facelet-taglib_1_0.dtd"); } transformer.setOutputProperty(OutputKeys.METHOD, "xml"); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.transform(source, new StreamResult(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(filename))))); return true; } catch (Exception e) { return false; } }
From source file:Main.java
public static void appendLog(String text) { File logFile = new File(Environment.getExternalStorageDirectory() + "/clr_log.file"); if (!logFile.exists()) { try {//from w ww. j a v a 2 s . c o m logFile.createNewFile(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } try { BufferedReader buf = new BufferedReader(new FileReader(logFile)); String line = ""; ArrayList<String> lines = new ArrayList<String>(); while ((line = buf.readLine()) != null) { lines.add(line); } int size = lines.size(); //Every time the number of lines go over 1000, only add the last 500. This will keep its size to a minimum int i = lines.size() - 500; if (i < 0) { i = 0; } buf.close(); BufferedWriter bufW = new BufferedWriter(new FileWriter(logFile, true)); if (size > 1000) { bufW.write(""); for (; i < lines.size(); i++) { bufW.append(line); } } bufW.append(text + "\n"); bufW.close(); } catch (IOException e) { e.printStackTrace(); } }
From source file:Main.java
/** * Print out the spike trains so it can be analyzed by plotting software * @param file/*from w w w . j a v a 2 s . c o m*/ * @param array */ public static void printArray(File file, double[] x, double[] y) { FileWriter fstream = null; BufferedWriter out = null; try { fstream = new FileWriter(file); out = new BufferedWriter(fstream); for (int i = 0; i < x.length; i++) { out.write(x[i] + "\t"); } out.write("\r\n"); for (int i = 0; i < y.length; i++) { out.write(y[i] + "\t"); } } catch (IOException e) { e.printStackTrace(); } finally { if (out != null) { try { out.close(); } catch (IOException e) { e.printStackTrace(); } } if (fstream != null) { try { fstream.close(); } catch (IOException e) { e.printStackTrace(); } } } }
From source file:Main.java
/** * //from ww w . jav a 2 s.c o m * @param os * @param request * @param charsetName * @throws IOException */ public static final void writeString(OutputStream os, String request, String charsetName) throws IOException { OutputStreamWriter writer = new OutputStreamWriter(os, charsetName); BufferedWriter bw = new BufferedWriter(writer); bw.write(request); bw.write("\r\n"); bw.flush(); }