Example usage for java.io FileWriter write

List of usage examples for java.io FileWriter write

Introduction

In this page you can find the example usage for java.io FileWriter write.

Prototype

public void write(int c) throws IOException 

Source Link

Document

Writes a single character.

Usage

From source file:com.mycompany.rent.controllers.MapController.java

@RequestMapping(value = "/data", method = RequestMethod.GET)
public File homePage(Map model) throws IOException {

    List<ForRent> allRentals = new ArrayList();

    allRentals = forRentDao.allRentals();

    JSONObject responseDetailsJson = new JSONObject();
    JSONArray array = new JSONArray();
    for (ForRent f : allRentals) {
        array.add(f.getLat());/*from w w w  .j  a  va 2  s . c o m*/
        array.add(f.getLon());
    }

    responseDetailsJson.put("data", (Object) array);//Here you can see the data in json format

    File file = new File("/home/brennan/_repos/rent/src/main/webapp/json/data.json");

    String path = file.getPath();

    try {

        // Writing to a file  
        file.createNewFile();
        FileWriter fileWriter = new FileWriter(file);

        fileWriter.write(responseDetailsJson.toJSONString());
        fileWriter.flush();
        fileWriter.close();

    } catch (IOException e) {

    }

    FileReader fr = new FileReader(file);

    return file;
}

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();//from   w ww . j  a va2 s . c o m

    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:com.linkedin.pinot.tools.admin.command.AbstractBaseAdminCommand.java

protected void savePID(String fileName) throws IOException {
    FileWriter pidFile = new FileWriter(fileName);
    pidFile.write(getPID());
    pidFile.close();/*from  www .jav  a2s .  c  o m*/
}

From source file:de.bley.word.filewriter.WriterFile.java

/**
 * Ueberschreibt den Inhalt einer Textdatei.
 *
 * @param filepath Pfad der zulesenden Datei.
 * @param text String, welcher in die Datei geschrieben werden soll.
 *
 *//*from   w  w w . jav  a  2  s. co m*/
@Override
public void overwriteFile(String filepath, String text) {

    try {
        FileWriter writer = new FileWriter(filepath, false);
        writer.write(text);
        writer.close();

    } catch (IOException e) {
        e.printStackTrace();
    }

}

From source file:de.bley.word.filewriter.WriterFile.java

/**
 * Schreibt Daten in eine Textdatei./*  w w w .  j av  a2 s  .  com*/
 *
 * @param filepath Pfad der zulesenden Datei.
 * @param text String, welcher in die Datei geschrieben werden soll.
 * @param flag Boolean, ob Text angehangen oder ueberschrieben werden soll.
 *
 */
@Override
public void writeInFile(String filepath, final String text, final boolean flag) {

    try {
        final FileWriter writer = new FileWriter(filepath, flag);
        writer.write(text + System.getProperty("line.separator"));
        writer.close();

    } catch (IOException ex) {
        ex.printStackTrace();
    }
}

From source file:com.xpn.xwiki.plugin.laszlo.LaszloPlugin.java

public String writeLaszloFile(String name, String laszlocode) throws IOException, XWikiException {
    File laszloDir = new File(laszloPath);
    if (!laszloDir.exists())
        laszloDir.mkdirs();//w  w  w  .j  av a 2  s.c o m

    String filename = getFileName(name, laszlocode);

    laszlocode = Util.secureLaszloCode(laszlocode);

    File dfile = new File(laszloDir, filename);
    if (!dfile.exists()) {
        FileWriter fwriter = new FileWriter(dfile);
        fwriter.write(laszlocode);
        fwriter.flush();
        fwriter.close();
    }

    return filename;
}

From source file:org.yestech.lib.io.FileSystemFileDownloadFilterUnitTest.java

@Test
public void testDefaultSettings() throws IOException, ServletException {
    String testFileName = "unittest.tst";
    File file = new File(System.getProperty("java.io.tmpdir"), testFileName);
    FileWriter writer = new FileWriter(file);
    String text = "testing download";
    writer.write(text);
    writer.flush();//from  w  w  w  . j  a v a2  s  .c o  m
    writer.close();
    //        config.addInitParameter("deleteAfterDownload", "false");
    //        config.addInitParameter("baseDirectory", "false");
    request.setParameter("file", testFileName);
    filter.doFilter(request, response, chain);
    assertEquals(text.length(), response.getContentLength());
    assertEquals(text, response.getContentAsString());
    assertTrue(file.exists());
    file.delete();
}

From source file:at.tuwien.minimee.migration.engines.MonitorEngineJIP.java

private void writeJIPconfigFile(long time) throws IOException {
    FileWriter w = new FileWriter(new File(makeConfigfileName(time)));
    w.write("ClassLoaderFilter.1=com.mentorgen.tools.profile.instrument.clfilter.StandardClassLoaderFilter\n");
    w.write("thread.compact.threshold.ms=1\n");
    w.write("method.compact.threshold.ms=1\n");
    w.write("file=");
    w.write(makeJIPOutFilename(time) + "\n"); //JIP will append .txt!
    w.write("track.object.alloc=on\n");
    w.write("output=text\n");
    w.write("output-method-signatures=yes");
    w.flush();//from  w  w w  . ja v  a2 s.c o m
    w.close();
}

From source file:com.flexive.tests.embedded.benchmark.logger.HudsonPlotLogger.java

@Override
protected void logResult(String name, double time, String measurement, String unit) {
    super.logResult(name, time, measurement, unit);
    final String filename = OUTPUT_DIRECTORY + File.separator + StringUtils.replace(name, File.separator, "_")
            + ".properties";
    if (!new File(OUTPUT_DIRECTORY).exists() && !new File(OUTPUT_DIRECTORY).mkdirs()) {
        LOG.warn("Failed to create output directory " + OUTPUT_DIRECTORY);
        return;//  w  w  w  .  ja v  a  2s . com
    }
    FileWriter fw = null;
    try {
        fw = new FileWriter(new File(filename));
        fw.write("YVALUE=" + time + "\n");
    } catch (IOException e) {
        LOG.error("Failed to write result file: " + e.getMessage(), e);
    } finally {
        if (fw != null) {
            try {
                fw.close();
            } catch (IOException e) {
                LOG.error("Failed to close file: " + e.getMessage(), e);
            }
        }
    }
}

From source file:de.fhg.iais.asc.viewspreview.ViewXmlScanner.java

private void closeFile(FileWriter filewriter) throws IOException {
    if (this.fileWriter != null) {
        filewriter.write("</body></html>");
        filewriter.close();/*from  ww w  .j av  a2 s .  c  o m*/
        this.filecounter++;
    }
}