List of usage examples for java.io BufferedWriter write
public void write(int c) throws IOException
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 www .j a v a 2 s . c o m*/ 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:bftsmart.tom.util.RSAKeyPairGenerator.java
private void saveToFile(int id, PublicKey puk, PrivateKey prk) throws Exception { String path = "config" + System.getProperty("file.separator") + "keys" + System.getProperty("file.separator"); BufferedWriter w = new BufferedWriter(new FileWriter(path + "publickey" + id, false)); w.write(getKeyAsString(puk)); w.flush();//from w w w . j av a2s.c om w.close(); w = new BufferedWriter(new FileWriter(path + "privatekey" + id, false)); w.write(getKeyAsString(prk)); w.flush(); w.close(); }
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);// w ww . ja v a 2s .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.Plus.Skript.SkriptManager.java
public void Enable(Extension s, String packages) throws IOException { try {//from w w w . j a v a 2 s .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:ir.pooyahfp.matrixcli.ProgramTest.java
@Test public void testLoadCommandFile() throws Exception { String path = "test.txt"; BufferedWriter writer = new BufferedWriter(new FileWriter(new File(path))); writer.write("matrix x 3 3"); writer.newLine();/* w w w .ja v a 2 s.c o m*/ writer.write("show x"); writer.flush(); writer.close(); program.loadCommandFile(path); }
From source file:eu.udig.catalog.jgrass.utils.JGrassCatalogUtilities.java
public static boolean createMapset(String locationPath, String mapset, CoordinateReferenceSystem crs, JGrassRegion window) {/* ww w. ja va 2s . co m*/ String path = locationPath + File.separator + mapset; /* Create mapset directory */ if (!(new File(path).mkdirs())) return false; if (mapset.equals(JGrassConstants.PERMANENT_MAPSET)) { /* Create blank DEFAULT_WIND and WIND files */ try { if (window != null) { JGrassRegion.writeWINDToMapset(path, window); JGrassRegion.writeDEFAULTWINDToLocation(locationPath, window); } else { // create blank windows BufferedWriter out = new BufferedWriter( new FileWriter(path + File.separator + JGrassConstants.DEFAULT_WIND)); out.write(JGrassRegion.BLACKBOARD_KEY); out.close(); out = new BufferedWriter(new FileWriter(path + File.separator + JGrassConstants.WIND)); out.write(JGrassRegion.BLANK_REGION); out.close(); } /* Create projection files */ if (crs != null) { // FIXME create GRASS proj files BufferedWriter prjOut = new BufferedWriter( new FileWriter(path + File.separator + JGrassConstants.PROJ_WKT)); prjOut.write(crs.toWKT()); prjOut.close(); } } catch (IOException e) { JGrassPlugin.log( "JGrassPlugin problem: eu.hydrologis.udig.catalog.utils#JGrassCatalogUtilities#createMapset", e); e.printStackTrace(); return false; } } else { /* Copy WIND file from PERMANENT mapset of this location */ try { BufferedReader in = new BufferedReader(new FileReader(locationPath + File.separator + JGrassConstants.PERMANENT_MAPSET + File.separator + JGrassConstants.DEFAULT_WIND)); BufferedWriter out = new BufferedWriter( new FileWriter(path + File.separator + JGrassConstants.WIND)); String line; while ((line = in.readLine()) != null) { out.write(line); out.write("\n"); } out.close(); in.close(); } catch (IOException e) { JGrassPlugin.log( "JGrassPlugin problem: eu.hydrologis.udig.catalog.utils#JGrassCatalogUtilities#createMapset", e); e.printStackTrace(); return false; } } /* Create point/site directories */ if (!(new File(path + File.separator + JGrassConstants.SITE_LISTS).mkdirs())) return false; /* Create raster directories */ if (!(new File(path + File.separator + JGrassConstants.FCELL).mkdirs())) return false; if (!(new File(path + File.separator + JGrassConstants.CELL).mkdirs())) return false; if (!(new File(path + File.separator + JGrassConstants.CELLHD).mkdirs())) return false; if (!(new File(path + File.separator + JGrassConstants.CATS).mkdirs())) return false; if (!(new File(path + File.separator + JGrassConstants.COLR).mkdirs())) return false; if (!(new File(path + File.separator + JGrassConstants.CELL_MISC).mkdirs())) return false; /* Create vector directories */ if (!(new File(path + File.separator + JGrassConstants.DIG).mkdirs())) return false; if (!(new File(path + File.separator + JGrassConstants.DIG_ATTS).mkdirs())) return false; if (!(new File(path + File.separator + JGrassConstants.DIG_CATS).mkdirs())) return false; if (!createJGrassFolders(path)) return false; return true; }
From source file:model.settings.ReadSettings.java
/** * reads text from a configuration file; if is configuration file * is not valid, return null; otherwise return configuration line. * /* w ww .java 2 s . c om*/ * @param _path from which _path is red. * @return the text read form file @ _path. * * @throws IOException is thrown in case of error. */ public static void changeOption(final String _operation, final String _newValue) throws IOException { //create Reader FileReader fr = new FileReader(PROGRAM_SETTINGS_LOCATION); BufferedReader br = new BufferedReader(fr); String sumLine = ""; String currentLine = ""; boolean found = false; currentLine = br.readLine(); while (currentLine != null) { if (!found) { sumLine += currentLine + "\n"; } else { found = !found; sumLine += _newValue + "\n"; } // if the current line is the identifier of the current // operation that has to be changed. if (currentLine != null && currentLine.equals(_operation)) { found = true; } currentLine = br.readLine(); } //close reader br.close(); fr.close(); FileWriter fw = new FileWriter(PROGRAM_SETTINGS_LOCATION); BufferedWriter bw = new BufferedWriter(fw); bw.write(sumLine); bw.flush(); bw.close(); fw.close(); }
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 ww w . j a va 2 s . 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.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 w ww . ja v a 2 s.co 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.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);//www . ja va2s.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(); }