List of usage examples for java.io BufferedWriter write
public void write(int c) throws IOException
From source file:com.thinkit.operationsys.util.FileUtil.java
public static void copyFile(String src, String dest) { System.out.println("copy"); File f1 = new File(src); File f2 = new File(dest); //int b=0;/*from w w w . j ava 2 s. c o m*/ String line = ""; try { FileReader reader = new FileReader(f1); FileWriter writer = new FileWriter(f2); BufferedReader br = new BufferedReader(reader); BufferedWriter bw = new BufferedWriter(writer); while ((line = br.readLine()) != null) { System.out.println(line); bw.write(line); bw.newLine(); bw.flush(); } reader.close(); writer.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:Main.java
public static boolean isRooted() { Process p;/*from ww w . j a va 2 s .c o m*/ try { p = new ProcessBuilder("su").start(); BufferedWriter stdin = new BufferedWriter(new OutputStreamWriter(p.getOutputStream())); BufferedReader stdout = new BufferedReader(new InputStreamReader(p.getInputStream())); stdin.write("whoami"); stdin.newLine(); stdin.write("exit"); stdin.newLine(); stdin.close(); try { p.waitFor(); if (!stdout.ready()) return false; String user = stdout.readLine(); //We only expect one line of output stdout.close(); if (user == "root") { return true; } else { return false; } } catch (InterruptedException e) { e.printStackTrace(); return false; } } catch (IOException e) { e.printStackTrace(); return false; } }
From source file:edu.cmu.cs.lti.ark.fn.data.prep.ParsePreparation.java
/** * Writes the given sentences to the given file * * @param outputFile the file to write to * @param sentences the sentences to write *//*from w w w .j a va 2 s. com*/ public static void writeSentencesToFile(String outputFile, List<String> sentences) { try { final BufferedWriter bWriter = new BufferedWriter(new FileWriter(outputFile)); for (String sentence : sentences) { bWriter.write(sentence.trim() + "\n"); } bWriter.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:net.amigocraft.mpt.Main.java
public static void initializeRepoStore(File file) { log.info("Initializing local repository store..."); try {//from w w w . j a v a2 s . com MiscUtil.lockStores(); JSONObject repos = new JSONObject(); // create an empty array repoStore = new JSONObject(); // create an empty object repoStore.put("repositories", repos); // add the array to it if (!file.getParentFile().exists()) file.getParentFile().mkdir(); file.createNewFile(); // create the file BufferedWriter writer = new BufferedWriter(new FileWriter(file)); // get a writer writer.write(JSONPrettyPrinter.toJSONString(repoStore)); // convert the JSON object to a string and write it writer.flush(); } catch (IOException ex) { ex.printStackTrace(); log.severe("Failed to initialize repository store!"); } catch (MPTException ex) { log.severe(ex.getMessage()); } MiscUtil.unlockStores(); }
From source file:be.ac.ua.comp.scarletnebula.core.KeyManager.java
/** * Takes a keyname, an actual key and a provider name (for which this key * works) and then stores the key on disk. * //from w ww . j a v a 2 s . c om * @param providerName * @param keyname * @param keystring */ static void addKey(final String providerName, final String keyname, final String keystring) { if (assureDirectory(providerName) == null) { return; } // Now store the key to file BufferedWriter out; try { out = new BufferedWriter(new FileWriter(getKeyFilename(providerName, keyname))); out.write(keystring); out.close(); } catch (final IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:com.slidespeech.server.service.TextToSpeechService.java
private static String createXML4Cereproc(String fileName, String speakernotes) throws IOException { List<String> voices = new ArrayList<String>(); try {/*from w w w . j a va2s. c o m*/ Document doc = Jsoup.parse(speakernotes, ""); doc.outputSettings().prettyPrint(false); Elements voiceNodes = doc.select("voice"); for (Element voiceNode : voiceNodes) { String lang = (voiceNode.hasAttr("xml:lang") && !voiceNode.attr("xml:lang").equals("")) ? voiceNode.attr("xml:lang") : "en"; String gender = (voiceNode.hasAttr("gender") && !voiceNode.attr("gender").equals("")) ? voiceNode.attr("gender") : "female"; String voiceName = (voiceNode.hasAttr("name") && !voiceNode.attr("name").equals("")) ? voiceNode.attr("name") : ""; //voice name not set by user -> choose one depending on language and gender if (voiceName.equals("")) { voiceName = "isabella";//default //if(lang.equalsIgnoreCase("en") && gender.equalsIgnoreCase("female")) voiceName = "isabella"; if (lang.equalsIgnoreCase("en") && gender.equalsIgnoreCase("male")) voiceName = "william"; if (lang.equalsIgnoreCase("de")) voiceName = "alex"; voiceNode.attr("name", voiceName); } if (!voices.contains(voiceName)) { voices.add(voiceName); } } BufferedWriter out = new BufferedWriter(new FileWriter(fileName)); out.write(doc.select("body").first().html()); //out.write(doc.select("body").first().html()); out.close(); for (int i = 0; i < voices.size(); i++) { if (voices.get(i).equals("william")) voices.set(i, "/opt/cereproc/cerevoice_william_3.0.5_22k.voice"); if (voices.get(i).equals("isabella")) voices.set(i, "/opt/cereproc/cerevoice_isabella_3.0.3_22k.voice"); if (voices.get(i).equals("alex")) voices.set(i, "/opt/cereproc/cerevoice_alex_3.0.0_beta_22k.voice"); } } catch (Exception e) { //Fallback if ssml parsing fails Writer out = new OutputStreamWriter(new FileOutputStream(fileName)); try { out.write(speakernotes); } finally { out.close(); } voices.add("ssml parsing failed"); } return StringUtils.join(voices, ","); }
From source file:com.wso2telco.services.bw.FileUtil.java
public static void fileWrite(String filePath, String data) throws IOException { BufferedWriter out = null; try {/*from w w w .j av a 2 s. c om*/ out = new BufferedWriter(new FileWriter(filePath)); out.write(data); } catch (IOException e) { e.printStackTrace(); } finally { out.close(); } }
From source file:Main.java
/** * Write the provided String, line by line, in the provided OutputStream. *///from w w w. ja v a2 s. c o m private static void writeStream(String toWrite, OutputStream out) throws IOException { BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(out)); BufferedReader reader = new BufferedReader(new StringReader(toWrite)); for (String line = reader.readLine(); line != null; line = reader.readLine()) { writer.write(line); } reader.close(); writer.close(); }
From source file:net.amigocraft.mpt.Main.java
public static void initializePackageStore(File file) { log.info("Initializing local package store..."); try {/*from w w w . j ava2 s. c o m*/ MiscUtil.lockStores(); JSONObject packages = new JSONObject(); // create an empty array packageStore = new JSONObject(); // create an empty object packageStore.put("packages", packages); // add the array to it try { if (!file.getParentFile().exists()) file.getParentFile().mkdir(); file.createNewFile(); // create the file BufferedWriter writer = new BufferedWriter(new FileWriter(file)); // get a writer writer.write(JSONPrettyPrinter.toJSONString(packageStore)); // convert the JSON object to a string and write it writer.flush(); } catch (IOException ex) { ex.printStackTrace(); log.severe("Failed to initialize package store!"); } MiscUtil.unlockStores(); } catch (MPTException ex) { log.severe(ex.getMessage()); } }
From source file:com.opensymphony.util.FileUtils.java
public final static void write(File file, String content) { try {// w w w . j a v a 2 s . c om BufferedWriter out = new BufferedWriter(new FileWriter(file)); out.write(content); out.close(); } catch (FileNotFoundException e) { log.warn("File not found", e); } catch (IOException e) { log.error(e); } }