List of usage examples for java.io FileWriter write
public void write(int c) throws IOException
From source file:id.co.nlp.MachineTranslation.Utils.Util.java
public static void write(String Url, String Teks) { FileWriter writer; try {/*from w ww .ja v a 2s . co m*/ writer = new FileWriter(Url); writer.write(Teks); writer.close(); } catch (IOException ex) { ex.printStackTrace(); } }
From source file:fridgegameinstaller.MCJsonConf.java
public static void getJson(String path, int mb) throws IOException { CloseableHttpClient httpclient = HttpClients.createDefault(); HttpGet httpGet = new HttpGet("http://api.fridgegame.com/mcconf/Fridgegame.json"); CloseableHttpResponse response1 = httpclient.execute(httpGet); try {// w w w . ja v a 2 s .co m System.out.println(httpGet.toString()); System.out.println(response1.getStatusLine()); BufferedReader br = new BufferedReader(new InputStreamReader(response1.getEntity().getContent())); String a; String output = ""; while ((a = br.readLine()) != null) { output += a + "\n"; } System.out.println(output); try { JSONObject json = new JSONObject(output); String mcArgs = json.getString("minecraftArguments"); String regex = "(-Xmx[^ ]*)"; Pattern p = Pattern.compile(regex); Matcher m = p.matcher(mcArgs); String newArgs = m.replaceAll("-Xmx" + mb + "M"); json.put("minecraftArguments", newArgs); FileWriter file = new FileWriter(path); try { file.write(json.toString()); } catch (IOException e) { e.printStackTrace(); } finally { file.flush(); file.close(); } } catch (JSONException e) { } } finally { response1.close(); } }
From source file:com.amazon.dtasdk.v2.signature.CredentialStoreTest.java
@BeforeClass public static void setUp() throws IOException { VALID_FILE = File.createTempFile("store", "csv"); FileWriter writer = new FileWriter(VALID_FILE); writer.write(String.format("%s %s\n", KEYS[0], KEYS[1])); // Intentionally check if blank lines are supported writer.write(String.format("%s %s\n\n", KEYS[2], KEYS[3])); writer.write(String.format("%s %s\n", KEYS[4], KEYS[5])); writer.write("\n"); writer.close();//from w w w . j av a2 s. co m INVALID_FILE = File.createTempFile("store", "csv"); writer = new FileWriter(INVALID_FILE); writer.write(String.format("%s%s\n", KEYS[0], KEYS[1])); writer.write(String.format("%s %s\n", KEYS[2], KEYS[3])); writer.write(String.format("%s %s\n", KEYS[4], KEYS[5])); writer.write("\n"); writer.close(); }
From source file:Main.java
public static boolean writeFile(String filePath, String content, boolean append) { FileWriter fileWriter = null; try {//from w ww . j ava2s. c om fileWriter = new FileWriter(filePath, append); fileWriter.write(content); fileWriter.close(); return true; } catch (IOException e) { throw new RuntimeException("IOException occurred. ", e); } finally { if (fileWriter != null) { try { fileWriter.close(); } catch (IOException e) { throw new RuntimeException("IOException occurred. ", e); } } } }
From source file:SageCollegeProject.guideBox.java
public static void WriteJsonToFile(String json, String fileName) { CheckMakeDir(fileName.substring(0, fileName.lastIndexOf("/"))); try {// w ww . j a v a 2s . co m FileWriter writer = new FileWriter(fileName); writer.write(json); writer.close(); } catch (IOException ex) { System.out.println("Error writing SCPGuideBox json file to disk"); System.out.println(ex); } }
From source file:ca.uvic.cs.tagsea.wizards.TagNetworkSender.java
public static synchronized void send(String xml, IProgressMonitor sendMonitor, int id) throws InvocationTargetException { sendMonitor.beginTask("Uploading Tags", 100); sendMonitor.subTask("Saving Temporary file..."); File location = TagSEAPlugin.getDefault().getStateLocation().toFile(); File temp = new File(location, "tagsea.temp.file.txt"); if (temp.exists()) { String message = "Unable to send tags. Unable to create temporary file."; IOException ex = new IOException(message); throw (new InvocationTargetException(ex, message)); }/*from ww w .ja v a 2 s. c o m*/ try { FileWriter writer = new FileWriter(temp); writer.write(xml); writer.flush(); writer.close(); } catch (IOException e) { throw new InvocationTargetException(e); } sendMonitor.worked(5); sendMonitor.subTask("Uploading Tags..."); String uploadScript = "http://stgild.cs.uvic.ca/cgi-bin/tagSEAUpload.cgi"; PostMethod post = new PostMethod(uploadScript); String fileName = getToday() + ".txt"; try { Part[] parts = { new StringPart("KIND", "tag"), new FilePart("MYLAR" + id, fileName, temp) }; post.setRequestEntity(new MultipartRequestEntity(parts, post.getParams())); HttpClient client = new HttpClient(); int status = client.executeMethod(post); String resp = getData(post.getResponseBodyAsStream()); if (status != 200) { IOException ex = new IOException(resp); throw (ex); } } catch (IOException e) { throw new InvocationTargetException(e, e.getLocalizedMessage()); } finally { sendMonitor.worked(90); sendMonitor.subTask("Deleting Temporary File"); temp.delete(); sendMonitor.done(); } }
From source file:com.ratebeer.android.gui.components.helpers.ImportExport.java
/** * Export the offline ratings from the database to a file * @param list The offline ratings to export * @param outputfile The file to write to * @throws JSONException Thrown when the content could not be written to JSON * @throws IOException Thrown when the file could not be written to *///from w w w. ja v a2 s.c o m public static void exportRatings(List<OfflineRating> list, File outputfile) throws JSONException, IOException { // Create a single JSON object with all offline ratings JSONObject json = new JSONObject(); JSONArray ratings = new JSONArray(); for (OfflineRating item : list) { JSONObject rating = new JSONObject(); rating.put("beerId", item.getBeerId()); rating.put("beerName", item.getBeerName()); rating.put("originalRatingId", item.getOriginalRatingId()); rating.put("originalRatingDate", item.getOriginalRatingDate()); rating.put("aroma", item.getAroma()); rating.put("appearance", item.getAppearance()); rating.put("taste", item.getTaste()); rating.put("palate", item.getPalate()); rating.put("overall", item.getOverall()); rating.put("comments", item.getComments()); rating.put("timeSaved", item.getTimeSaved().getTime()); ratings.put(rating); } json.put("ratings", ratings); // Serialize the JSON object to a file if (outputfile.exists()) { outputfile.delete(); } outputfile.getParentFile().mkdirs(); outputfile.createNewFile(); FileWriter writer = new FileWriter(outputfile); writer.write(json.toString(2)); writer.flush(); writer.close(); }
From source file:Main.java
public static int removeUnusedLines(String filename, SortedSet<Integer> linesSet) { try {//from ww w.j a va 2 s . co m BufferedReader br = new BufferedReader(new FileReader(filename)); //String buffer to store contents of the file StringBuffer sb = new StringBuffer(""); int lineNumber = 1; String line; Iterator iterator = linesSet.iterator(); int lineNumberToBeDeleted = (int) iterator.next(); int count = 0; while ((line = br.readLine()) != null) { if (lineNumber == lineNumberToBeDeleted) { if (iterator.hasNext()) { lineNumberToBeDeleted = (int) iterator.next(); count++; } } else { sb.append(line + "\n"); } lineNumber++; } FileWriter fw = new FileWriter(new File(filename)); //Write entire string buffer into the file fw.write(sb.toString()); fw.close(); System.err.println("deleted lines" + count); } catch (Exception e) { System.err.println("error:" + e.getMessage()); e.printStackTrace(); return -10; } return 10; }
From source file:me.ardacraft.blocksapi.helper.LangHelper.java
public static void writeLangFile() { File out = FileHelper.externalConfigFile("assets/acblocks/lang", "en_US.lang"); try {//ww w . j ava 2 s . com FileWriter writer = new FileWriter(out); Collections.sort(entries); for (String s : entries) { writer.write(s); writer.append("\n"); } writer.close(); } catch (IOException e) { e.printStackTrace(); } entries.clear(); }
From source file:edu.isi.karma.util.FileUtil.java
public static void writePrettyPrintedJSONObjectToFile(JSONObject json, File jsonFile) throws JSONException, IOException { String prettyPrintedJSONString = json.toString(4); FileWriter writer = new FileWriter(jsonFile); writer.write(prettyPrintedJSONString); writer.close();//from w w w.j av a 2 s . c om logger.debug("Done writing JSON Object into a File: " + jsonFile.getAbsolutePath()); }