List of usage examples for java.io FileWriter close
public void close() throws IOException
From source file:com.googlecode.t7mp.util.CommonsSetupUtilTest.java
@Before public void setUp() throws IOException { catalinaBaseDir = Files.createTempDir(); source = File.createTempFile("source", ".tmp"); source.deleteOnExit();/*from www . j av a 2 s. c o m*/ target = File.createTempFile("target", ".tmp"); target.deleteOnExit(); FileWriter sourceWriter = new FileWriter(source); sourceWriter.write(MESSAGE); sourceWriter.close(); }
From source file:com.googlecode.t7mp.CommonsSetupUtilTest.java
@Before public void setUp() throws IOException { catalinaBaseDir = new File(new File(System.getProperty("java.io.tmpdir")), "catalinaBase_" + (++counter)); catalinaBaseDir.mkdirs();//ww w. ja v a2s. c om source = File.createTempFile("source", ".tmp"); source.deleteOnExit(); target = File.createTempFile("target", ".tmp"); target.deleteOnExit(); FileWriter sourceWriter = new FileWriter(source); sourceWriter.write(MESSAGE); sourceWriter.close(); }
From source file:voldemort.ServerTestUtils.java
public static VoldemortConfig createServerConfigWithDefs(boolean useNio, int nodeId, String baseDir, Cluster cluster, List<StoreDefinition> stores, Properties properties) throws IOException { File clusterXml = new File(TestUtils.createTempDir(), "cluster.xml"); File storesXml = new File(TestUtils.createTempDir(), "stores.xml"); ClusterMapper clusterMapper = new ClusterMapper(); StoreDefinitionsMapper storeDefMapper = new StoreDefinitionsMapper(); FileWriter writer = new FileWriter(clusterXml); writer.write(clusterMapper.writeCluster(cluster)); writer.close(); writer = new FileWriter(storesXml); writer.write(storeDefMapper.writeStoreList(stores)); writer.close();/* w w w.ja v a 2 s. c o m*/ return createServerConfig(useNio, nodeId, baseDir, clusterXml.getAbsolutePath(), storesXml.getAbsolutePath(), properties); }
From source file:idp.file_operator.java
public void save_csv(int file_count) { try {// w w w . j a v a 2 s. c o m for (int i = 0; i < file_count; i++) { FileWriter writer = new FileWriter(path + gui.jTabbedPane1.getTitleAt(i)); writer.write(gui.jta.get(i).getText()); writer.close(); } } catch (IOException ex) { } }
From source file:de.hstsoft.sdeep.Configuration.java
@SuppressWarnings("unchecked") public void save() { JSONObject jsonObject = new JSONObject(); jsonObject.put(PREF_SAVEGAME_PATH, saveGamePath); jsonObject.put(PREF_AUTOREFRESH, autorefresh); try {//ww w . j av a2s .c o m String jsonString = jsonObject.toJSONString(); FileWriter fileWriter = new FileWriter(configFile); fileWriter.append(jsonString); fileWriter.flush(); fileWriter.close(); } catch (IOException e) { e.printStackTrace(); } }
From source file:at.tugraz.sss.serv.SSFileU.java
public static void appendTextToFile(String filePath, String text) throws Exception { FileWriter fileWriter = null; BufferedWriter bufferWritter = null; try {//from w ww .j av a2 s .co m fileWriter = new FileWriter(filePath, true); bufferWritter = new BufferedWriter(fileWriter); bufferWritter.write(text); } catch (IOException error) { throw error; } finally { if (bufferWritter != null) { bufferWritter.close(); } if (fileWriter != null) { fileWriter.close(); } } }
From source file:jetbrains.exodus.util.CompressBackupUtilTest.java
@Test public void testFolderArchived() throws Exception { File src = new File(randName); src.mkdir();// ww w .j av a2 s . c o m FileWriter fw = new FileWriter(new File(src, "1.txt")); fw.write("12345"); fw.close(); fw = new FileWriter(new File(src, "2.txt")); fw.write("12"); fw.close(); CompressBackupUtil.tar(src, dest); Assert.assertTrue("No destination archive created", dest.exists()); TarArchiveInputStream tai = new TarArchiveInputStream( new GZIPInputStream(new BufferedInputStream(new FileInputStream(dest)))); ArchiveEntry entry1 = tai.getNextEntry(); ArchiveEntry entry2 = tai.getNextEntry(); if (entry1.getName().compareTo(entry2.getName()) > 0) { // kinda sort them lol ArchiveEntry tmp = entry1; entry1 = entry2; entry2 = tmp; } Assert.assertNotNull("No entry found in destination archive", entry1); Assert.assertEquals("Entry has wrong size", 5, entry1.getSize()); System.out.println(entry1.getName()); Assert.assertEquals("Entry has wrong relative path", src.getName() + "/1.txt", entry1.getName()); System.out.println(entry2.getName()); Assert.assertEquals("Entry has wrong size", 2, entry2.getSize()); Assert.assertEquals("Entry has wrong relative path", src.getName() + "/2.txt", entry2.getName()); }
From source file:gov.nih.nci.caarray.plugins.agilent.EndOfLineCorrectingReaderTest.java
private File createTestFile() throws IOException { File file = File.createTempFile("EndOfLineCorrectingReaderTest", null); file.deleteOnExit();/*from w w w. j a v a 2 s . c o m*/ final FileWriter fileWriter = new FileWriter(file); try { IOUtils.copy(new StringReader(originalData), fileWriter); } finally { fileWriter.close(); } return file; }
From source file:com.yunmel.syncretic.utils.io.IOUtils.java
/** * /*ww w . j a v a 2 s .com*/ * * @param content * @param filePath */ public static void writeFile(String content, String filePath) { try { if (IOUtils.createFile(filePath)) { FileWriter fileWriter = new FileWriter(filePath, true); BufferedWriter bufferedWriter = new BufferedWriter(fileWriter); bufferedWriter.write(content); bufferedWriter.close(); fileWriter.close(); } else { log.info("??"); } } catch (Exception e) { e.printStackTrace(); } }
From source file:com.tealeaf.Downloader.java
protected void write(File f, String contents) { try {/*ww w. j a va2s . co m*/ if (!f.exists()) { File dir = new File(f.getParent()); dir.mkdirs(); f.createNewFile(); } FileWriter fw = new FileWriter(f); fw.write(contents); fw.close(); } catch (IOException e) { logger.log(e); } }