List of usage examples for java.io BufferedWriter write
public void write(int c) throws IOException
From source file:Main.java
public static boolean writeFile(String filename, String content) { boolean isSuccess = false; BufferedWriter bufferedWriter = null; try {/*from ww w.j ava2 s .c om*/ bufferedWriter = new BufferedWriter(new FileWriter(filename, false)); bufferedWriter.write(content); isSuccess = true; } catch (IOException e) { e.printStackTrace(); } finally { closeIO(bufferedWriter); } return isSuccess; }
From source file:edu.american.student.stonewall.util.Deployer.java
private static void save(String source, String name, File destination) throws IOException { if (!destination.exists()) { destination.mkdirs();//from w w w. jav a 2 s . com } // Create file FileWriter fstream = new FileWriter(destination.getAbsolutePath() + File.separator + name); BufferedWriter out = new BufferedWriter(fstream); out.write(source); // Close the output stream out.close(); }
From source file:files.FileUtils.java
public static boolean WriteDatFile(String pathFileText, String fileContent) { try {/*from 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:Main.java
public static boolean writeFile(String filename, String content, boolean append) { boolean isSuccess = false; BufferedWriter bufferedWriter = null; try {/*from w ww. j a v a 2 s. c om*/ bufferedWriter = new BufferedWriter(new FileWriter(filename, append)); bufferedWriter.write(content); isSuccess = true; } catch (IOException e) { e.printStackTrace(); } finally { closeIO(bufferedWriter); } return isSuccess; }
From source file:Main.java
public static void writeContentToFile(String fileName, String contents) throws IOException { Log.d("writeContentToFile", fileName); File f = new File(fileName); f.getParentFile().mkdirs();/*w w w .j a v a 2 s . c o m*/ File tempFile = new File(fileName + ".tmp"); FileWriter fw = new FileWriter(tempFile); BufferedWriter bw = new BufferedWriter(fw); int length = contents.length(); if (length > 0) { bw.write(contents); // int apart = Math.min(length, 65536); // int times = length / apart; // for (int i = 0; i < times; i++) { // bw.write(contents, i * apart, apart); // } // if (length % apart != 0) { // bw.write(contents, times * apart, length - times * apart); // } bw.flush(); fw.flush(); bw.close(); fw.close(); f.delete(); tempFile.renameTo(f); } }
From source file:com.vaadin.buildhelpers.CompileTheme.java
private static void processSassTheme(String themeFolder, String themeName, String variant, String version) throws Exception { StringBuffer cssHeader = new StringBuffer(); version = version.replaceAll("\\.", "_"); cssHeader.append(".v-theme-version:after {content:\"" + version + "\";}\n"); cssHeader.append(".v-theme-version-" + version + " {display: none;}\n"); String stylesCssDir = themeFolder + File.separator + themeName + File.separator; String stylesCssName = stylesCssDir + variant + ".css"; // Process as SASS file String sassFile = stylesCssDir + variant + ".scss"; ScssStylesheet scss = ScssStylesheet.get(sassFile); if (scss == null) { throw new IllegalArgumentException("SASS file: " + sassFile + " not found"); }/*from w ww.j a va 2s . co m*/ scss.compile(); BufferedWriter out = new BufferedWriter(new FileWriter(stylesCssName)); out.write(cssHeader.toString()); out.write(scss.toString()); out.close(); System.out.println("Compiled CSS to " + stylesCssName + " (" + scss.toString().length() + " bytes)"); createSprites(themeFolder, themeName); File oldCss = new File(stylesCssName); File newCss = new File(stylesCssDir + variant + "-sprite.css"); if (newCss.exists()) { // Theme contained sprites. Renamed "styles-sprite.css" -> // "styles.css" oldCss.delete(); boolean ok = newCss.renameTo(oldCss); if (!ok) { throw new RuntimeException("Rename " + newCss + " -> " + oldCss + " failed"); } } }
From source file:Main.java
public static String UpdateScore(String userName, int br) { String retStr = ""; try {//w w w.j av a2 s. co m URL url = new URL("http://" + IP_ADDRESS + "/RiddleQuizApp/ServerSide/AzurirajHighScore.php"); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setConnectTimeout(15000); conn.setReadTimeout(10000); conn.setRequestMethod("POST"); conn.setDoInput(true); conn.setDoOutput(true); Log.e("http", "por1"); JSONObject data = new JSONObject(); data.put("username", userName); data.put("broj", br); Log.e("http", "por3"); Uri.Builder builder = new Uri.Builder().appendQueryParameter("action", data.toString()); String query = builder.build().getEncodedQuery(); Log.e("http", "por4"); OutputStream os = conn.getOutputStream(); BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(os, "UTF-8")); bw.write(query); Log.e("http", "por5"); bw.flush(); bw.close(); os.close(); int responseCode = conn.getResponseCode(); Log.e("http", String.valueOf(responseCode)); if (responseCode == HttpURLConnection.HTTP_OK) { retStr = inputStreamToString(conn.getInputStream()); } else retStr = String.valueOf("Error: " + responseCode); Log.e("http", retStr); } catch (Exception e) { Log.e("http", "greska"); } return retStr; }
From source file:Main.java
public static String UdatePlayerBT(String userName, String device) { String retStr = ""; try {// ww w. ja v a 2s. c o m URL url = new URL("http://" + IP_ADDRESS + "/RiddleQuizApp/ServerSide/PostaviBTdevice.php"); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setConnectTimeout(15000); conn.setReadTimeout(10000); conn.setRequestMethod("POST"); conn.setDoInput(true); conn.setDoOutput(true); Log.e("http", "por1"); JSONObject data = new JSONObject(); data.put("username", userName); data.put("bt_device", device); Log.e("http", "por3"); Uri.Builder builder = new Uri.Builder().appendQueryParameter("action", data.toString()); String query = builder.build().getEncodedQuery(); Log.e("http", "por4"); OutputStream os = conn.getOutputStream(); BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(os, "UTF-8")); bw.write(query); Log.e("http", "por5"); bw.flush(); bw.close(); os.close(); int responseCode = conn.getResponseCode(); Log.e("http", String.valueOf(responseCode)); if (responseCode == HttpURLConnection.HTTP_OK) { retStr = inputStreamToString(conn.getInputStream()); } else retStr = String.valueOf("Error: " + responseCode); Log.e("http", retStr); } catch (Exception e) { Log.e("http", "greska"); } return retStr; }
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 ava2 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
/** * // w ww . j a va2 s . co 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(); } }