List of usage examples for java.io BufferedWriter close
@SuppressWarnings("try") public void close() throws IOException
From source file:jsonconverter.createandwrite.JSONFileWriter.java
public void createFile(String name, String JSONFolderPath) { try {//from w w w. j a va 2s . c o m File file = new File(JSONFolderPath, name + ".txt"); file.createNewFile(); FileWriter fw = new FileWriter(file); BufferedWriter bw = new BufferedWriter(fw); bw.write(obj.toString()); bw.flush(); bw.close(); } catch (IOException e) { e.printStackTrace(); } }
From source file:net.estinet.gFeatures.Feature.CTF.Confligs.ConfligInit.java
public void MakeFile(String filename) throws IOException { Reader paramReader = new InputStreamReader(getClass().getResourceAsStream(filename + ".yml")); StringWriter writer = new StringWriter(); IOUtils.copy(paramReader, writer);/* ww w. ja va2s . co m*/ String theString = writer.toString(); File f = new File("plugins/CrackShot/weapons/" + filename + ".yml"); f.createNewFile(); BufferedWriter bw = new BufferedWriter(new FileWriter(f)); bw.write(theString); bw.close(); }
From source file:com.pimp.companionforband.utils.jsontocsv.writer.CSVWriter.java
private void close(BufferedWriter writer) { try {//w w w.ja va 2 s . c om if (writer != null) { writer.close(); } } catch (IOException e) { e.printStackTrace(); } }
From source file:magixcel.FileMan.java
static void writeToFile() { FileOutputStream fos = null;/*from ww w . j a va2 s.c o m*/ OutputStreamWriter osw = null; BufferedWriter bw = null; String fileNameFull = OUTPUT_FILE_DIRECTORY + "output.txt"; System.out.println("writing to: " + fileNameFull); try { fos = new FileOutputStream(fileNameFull); osw = new OutputStreamWriter(fos, Charsets.ISO_8859_1); bw = new BufferedWriter(osw); for (String lineOut : OutputFormat.getOutputLines()) { if (Globals.DEVELOPER_MODE == 1) { System.out.println("Writing line: " + lineOut); } bw.write(lineOut + System.lineSeparator()); } System.out.println("DONE"); } catch (FileNotFoundException ex) { Logger.getLogger(FileMan.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(FileMan.class.getName()).log(Level.SEVERE, null, ex); } finally { try { bw.close(); osw.close(); fos.close(); } catch (IOException ex) { Logger.getLogger(FileMan.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:net.genesishub.gFeatures.Plus.Skript.SkriptManager.java
public void Enable(Extension s, String packages) throws IOException { try {/*from ww w. ja v a 2s . c o m*/ Reader paramReader = new InputStreamReader(getClass().getResourceAsStream( "/net/genesishub/gFeatures/Plus/Skript/" + packages + "/" + s.getName() + ".sk")); StringWriter writer = new StringWriter(); IOUtils.copy(paramReader, writer); String theString = writer.toString(); File f = new File("plugins/Skript/scripts/" + s.toString() + ".sk"); f.createNewFile(); BufferedWriter bw = new BufferedWriter(new FileWriter(f, true)); bw.write(theString); bw.close(); } catch (Exception E) { } }
From source file:it.evilsocket.dsploit.core.System.java
public static synchronized void errorLogging(String tag, Exception e) { String message = "Unknown error.", trace = "Unknown trace.", filename = (new File(Environment.getExternalStorageDirectory().toString(), ERROR_LOG_FILENAME)) .getAbsolutePath();//from w w w .ja v a2 s . com if (e != null) { if (e.getMessage() != null && e.getMessage().isEmpty() == false) message = e.getMessage(); else if (e.toString() != null) message = e.toString(); Writer sWriter = new StringWriter(); PrintWriter pWriter = new PrintWriter(sWriter); e.printStackTrace(pWriter); trace = sWriter.toString(); if (mContext != null && getSettings().getBoolean("PREF_DEBUG_ERROR_LOGGING", false) == true) { try { FileWriter fWriter = new FileWriter(filename, true); BufferedWriter bWriter = new BufferedWriter(fWriter); bWriter.write(trace); bWriter.close(); } catch (IOException ioe) { Log.e(TAG, ioe.toString()); } } } setLastError(message); Log.e(tag, message); Log.e(tag, trace); }
From source file:com.galenframework.tests.utils.GalenUtilsTest.java
@Test public void shouldReadRelativePath() throws Exception { File baseDir = new File(System.getProperty("java.io.tmpdir")); File tempDir = new File(baseDir, "galen_test"); tempDir.mkdir();//from ww w. j a va2s.c o m File testFile1 = new File(tempDir, "testFile.txt"); BufferedWriter output = new BufferedWriter(new FileWriter(testFile1)); output.write(""); output.close(); File testFile2 = new File(baseDir, "testFile2.txt"); BufferedWriter output2 = new BufferedWriter(new FileWriter(testFile2)); output2.write(""); output2.close(); InputStream fileStream1 = GalenUtils.findFileOrResourceAsStream(testFile1.getAbsolutePath()); assertThat(fileStream1, notNullValue()); InputStream fileStream2 = GalenUtils.findFileOrResourceAsStream( tempDir.toString() + File.separator + ".." + File.separator + "testFile2.txt"); assertThat(fileStream2, notNullValue()); FileUtils.deleteQuietly(tempDir); FileUtils.deleteQuietly(testFile2); }
From source file:net.genesishub.gFeatures.Feature.gWarsSuiteOld.CrackshotConfiguration.java
public void MakeFile(String filename) throws IOException { Reader paramReader = new InputStreamReader( getClass().getResourceAsStream("/tk/genesishub/gFeatures/gWarsSuite/WeaponConfig/" + filename)); StringWriter writer = new StringWriter(); IOUtils.copy(paramReader, writer);//from w w w . ja v a 2 s .c o m String theString = writer.toString(); File f = new File("plugins/CrackShot/weapons/" + filename + ".yml"); f.createNewFile(); BufferedWriter bw = new BufferedWriter(new FileWriter(f)); bw.write(theString); bw.close(); }
From source file:net.estinet.gFeatures.Feature.gWarsSuite.Configuration.java
public void MakeFile(String filename) throws IOException { Reader paramReader = new InputStreamReader( getClass().getResourceAsStream("/net/estinet/gFeatures/Feature/gWarsSuite/" + filename)); StringWriter writer = new StringWriter(); IOUtils.copy(paramReader, writer);/*from w w w . java2 s . c o m*/ String theString = writer.toString(); File f = new File("plugins/CrackShot/weapons/" + filename + ".yml"); f.createNewFile(); BufferedWriter bw = new BufferedWriter(new FileWriter(f)); bw.write(theString); bw.close(); }
From source file:net.genesishub.gFeatures.Feature.gWarsSuite.Configs.CrackshotConfiguration.java
public void MakeFile(String filename) throws IOException { Reader paramReader = new InputStreamReader( getClass().getResourceAsStream("/net/genesishub/gFeatures/Feature/gWarsSuite/Configs/" + filename)); StringWriter writer = new StringWriter(); IOUtils.copy(paramReader, writer);//from w w w . j a v a2 s. com String theString = writer.toString(); File f = new File("plugins/CrackShot/weapons/" + filename + ".yml"); f.createNewFile(); BufferedWriter bw = new BufferedWriter(new FileWriter(f)); bw.write(theString); bw.close(); }