Example usage for java.io FileWriter append

List of usage examples for java.io FileWriter append

Introduction

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

Prototype

@Override
    public Writer append(CharSequence csq) throws IOException 

Source Link

Usage

From source file:Main.java

public static void main(String[] args) throws Exception {
    FileWriter fileWriter = new FileWriter("c:/abc.txt");
    fileWriter.append("java2s.com");
    fileWriter.close();/*from  w w  w  . j a v a2 s.com*/

}

From source file:Main.java

public static void main(String[] args) throws Exception {
    FileWriter fileWriter = new FileWriter("c:/abc.txt", true);
    fileWriter.append("java2s.com");
    fileWriter.close();/*from w w  w  .j a  v  a  2  s  .  co m*/

}

From source file:Main.java

public static void main(String[] args) throws Exception {
    FileWriter fileWriter = new FileWriter(new File("c:/abc.txt"));
    fileWriter.append("java2s.com");
    fileWriter.close();//from  ww w.  j ava  2  s  .  com

}

From source file:Main.java

public static void main(String[] args) throws Exception {
    FileWriter fileWriter = new FileWriter(new File("c:/abc.txt"), true);
    fileWriter.append("java2s.com");
    fileWriter.close();/*from   www.  j a  va 2 s. c om*/

}

From source file:Main.java

public static void main(String[] args) throws Exception {
    FileWriter fileWriter = new FileWriter(new FileOutputStream("c:/abc.txt").getFD());
    fileWriter.append("java2s.com");
    fileWriter.close();/* ww w.  j av  a2  s  .c o m*/

}

From source file:org.apache.groovy.perf.CompilerPerformanceTest.java

public static void main(String[] args) throws Exception {
    List<File> sources = new ArrayList<>();
    List<URL> classpath = new ArrayList<>();
    boolean isCp = false;
    for (String arg : args) {
        if ("-cp".equals(arg)) {
            isCp = true;//from w w  w .  jav  a  2s  . c om
        } else if (isCp) {
            classpath.add(new File(arg).toURI().toURL());
        } else {
            sources.add(new File(arg));
        }
    }
    ScriptCompilationExecuter executer = new ScriptCompilationExecuter(
            sources.toArray(new File[sources.size()]), classpath);
    System.out.println("Using Groovy " + GROOVY_VERSION);

    DescriptiveStatistics stats = new DescriptiveStatistics();

    for (int i = 0; i < WARMUP + REPEAT; i++) {
        if (i < WARMUP) {
            System.out.println("Warmup #" + (i + 1));
        } else {
            System.out.println("Round #" + (i - WARMUP));
        }
        long dur = executer.execute();
        System.gc();
        System.out.printf("Compile time = %dms%n", dur);
        if (i >= WARMUP) {
            stats.addValue((double) dur);
        }
    }

    System.out.println("Compilation took " + stats.getMean() + "ms  " + stats.getStandardDeviation() + "ms");
    FileWriter wrt = new FileWriter(new File("target/compilation-stats.csv"), true);
    wrt.append(String.format("%s;%s;%s\n", GROOVY_VERSION, stats.getMean(), stats.getStandardDeviation()));
    wrt.close();
}

From source file:edu.berkeley.compbio.ncbitaxonomy.Exporter.java

public static void main(String[] argv) {
    try {/*from   ww w. j a  v  a  2s  .  c o  m*/
        ApplicationContext ctx = NcbiTaxonomyDbContextFactory.makeNcbiTaxonomyDbContext();
        NcbiTaxonomyPhylogeny ncbi = (NcbiTaxonomyPhylogeny) ctx.getBean("ncbiTaxonomyPhylogeny");

        FileWriter treeWriter = new FileWriter("tree.newick");
        ncbi.toNewick(treeWriter, "", "", 0, 0);
        treeWriter.close();

        FileWriter synonymWriter = new FileWriter("synonyms");
        ncbi.writeSynonyms(synonymWriter);
        synonymWriter.close();

        for (String rank : ranks) {
            FileWriter rankWriter = new FileWriter(rank);
            Set<Integer> ids = ncbi.getTaxIdsWithRank(rank);
            for (Integer id : ids) {
                rankWriter.append(id.toString()).append("\n");
            }
            rankWriter.close();
        }
    } catch (Throwable e) {
        e.printStackTrace();
    }
}

From source file:eu.smartfp7.terrier.sensor.CouchDBTimeCrowdPlotter.java

public static void main(String[] args) throws IOException {

    Database db = new Database("dusk.ait.gr/couchdb", 80, "smart_test_crowd");

    DesignDocument designDocument = db.getDesignDocument("getTimeNdensity");

    View view = designDocument.getView("timeNdensity");

    ViewResult<Object> vr = db.query("_design/getTimeNdensity/_view/timeNdensity", Object.class, new Options(),
            new JSONParser(), null);

    FileWriter fileWriter = new FileWriter(new File(args[0]));

    for (ValueRow<Object> v : vr.getRows()) {
        System.out.println(v.getKey() + "," + v.getValue());
        fileWriter.append(v.getKey() + "," + v.getValue() + "\n");
    }/*from   w  w  w  . j a  va  2  s.co  m*/

}

From source file:org.projectforge.core.CreateImageDimensions.java

public static void main(final String[] args) throws IOException {
    log.info("Create dimension file of all webapp images.");
    final List<ImageDimension> dimensions = new ArrayList<ImageDimension>();
    for (final String subDir : SUB_DIRS) {
        final String path = PATH + subDir;
        final Collection<File> files = FileUtils.listFiles(new File(path), IMAGE_SUFFIXES, true);
        final File absolutePathFile = new File(PATH);
        final String absolutePath = absolutePathFile.getAbsolutePath();
        for (final File file : files) {
            final Image image = Toolkit.getDefaultToolkit().getImage(file.getAbsolutePath());
            final ImageIcon icon = new ImageIcon(image);
            final String filename = file.getAbsolutePath().substring(absolutePath.length() + 1);
            final ImageDimension dimension = new ImageDimension(filename, icon.getIconWidth(),
                    icon.getIconHeight());
            dimensions.add(dimension);/*from www  .ja va 2 s .  c om*/
        }
    }
    final FileWriter writer = new FileWriter(DIMENSION_FILE);
    final XmlObjectWriter xmlWriter = new XmlObjectWriter();
    final AliasMap aliasMap = new AliasMap();
    aliasMap.put(ArrayList.class, "images");
    xmlWriter.setAliasMap(aliasMap);
    final String xml = xmlWriter.writeToXml(dimensions, true);
    writer.append(XmlHelper.XML_HEADER);
    writer.append(xml);
    IOUtils.closeQuietly(writer);
    log.info("Creation of dimension file done: " + DIMENSION_FILE);
}

From source file:com.thed.zapi.cloud.sample.CycleExecutionReportByVersion.java

public static void main(String[] args) throws JSONException, URISyntaxException, ParseException, IOException {

    String API_GET_EXECUTIONS = "{SERVER}/public/rest/api/1.0/executions/search/cycle/";
    String API_GET_CYCLES = "{SERVER}/public/rest/api/1.0/cycles/search?";
    // Delimiter used in CSV file
    final String NEW_LINE_SEPARATOR = "\n";
    final String fileName = "F:\\cycleExecutionReport.csv";

    /** Declare JIRA,Zephyr URL,access and secret Keys */
    // JIRA Cloud URL of the instance
    String jiraBaseURL = "https://demo.atlassian.net";
    // Replace zephyr baseurl <ZAPI_Cloud_URL> shared with the user for ZAPI Cloud Installation
    String zephyrBaseUrl = "<ZAPI_Cloud_URL>";
    // zephyr accessKey , we can get from Addons >> zapi section
    String accessKey = "YjE2MjdjMGEtNzExNy0zYjY1LWFkMzQtNjcwMDM3OTljFkbWluIGFkbWlu";
    // zephyr secretKey , we can get from Addons >> zapi section
    String secretKey = "qufnbimi96Ob2hq3ISF08yZ8Qw4c1eHGeGlk";

    /** Declare parameter values here */
    String userName = "admin";
    String versionId = "-1";
    String projectId = "10100";
    String projectName = "Support";
    String versionName = "Unscheduled";

    ZFJCloudRestClient client = ZFJCloudRestClient.restBuilder(zephyrBaseUrl, accessKey, secretKey, userName)
            .build();//from w w w .ja  v  a 2 s. c  o  m
    /**
     * Get List of Cycles by Project and Version
     */

    final String getCyclesUri = API_GET_CYCLES.replace("{SERVER}", zephyrBaseUrl) + "projectId=" + projectId
            + "&versionId=" + versionId;

    Map<String, String> cycles = getCyclesByProjectVersion(getCyclesUri, client, accessKey);
    // System.out.println("cycles :"+ cycles.toString());

    /**
     * Iterating over the Cycles and writing the report to CSV
     * 
     */

    FileWriter fileWriter = null;
    System.out.println("Writing CSV file.....");
    try {
        fileWriter = new FileWriter(fileName);

        // Write the CSV file header

        fileWriter.append("Cycle Execution Report By Version and Project");
        fileWriter.append(NEW_LINE_SEPARATOR);
        fileWriter.append("PROJECT:" + "," + projectName);
        fileWriter.append(NEW_LINE_SEPARATOR);
        fileWriter.append("VERSION:" + "," + versionName);
        fileWriter.append(NEW_LINE_SEPARATOR);

        JSONArray executions;
        int totalUnexecutedCount = 0;
        int totalExecutionCount = 0;

        for (String key : cycles.keySet()) {
            int executionCount = 0;
            int unexecutedCount = 0;
            final String getExecutionsUri = API_GET_EXECUTIONS.replace("{SERVER}", zephyrBaseUrl) + key
                    + "?projectId=" + projectId + "&versionId=" + versionId;
            fileWriter.append("Cycle:" + "," + cycles.get(key));
            fileWriter.append(NEW_LINE_SEPARATOR);
            executions = getExecutionsByCycleId(getExecutionsUri, client, accessKey);
            // System.out.println("executions :" + executions.toString());

            HashMap<String, Integer> counter = new HashMap<String, Integer>();

            String[] statusName = new String[executions.length()];
            for (int i = 0; i < executions.length(); i++) {
                JSONObject executionObj = executions.getJSONObject(i).getJSONObject("execution");
                // System.out.println("executionObj
                // "+executionObj.toString());
                JSONObject statusObj = executionObj.getJSONObject("status");
                // System.out.println("statusObj :"+statusObj.toString());
                statusName[i] = statusObj.getString("name");
            }

            if (statusName.length != 0) {
                // System.out.println(statusName.toString());
                for (String a : statusName) {
                    if (counter.containsKey(a)) {
                        int oldValue = counter.get(a);
                        counter.put(a, oldValue + 1);
                    } else {
                        counter.put(a, 1);
                    }
                }
                for (String status : counter.keySet()) {
                    fileWriter.append(" " + "," + " " + "," + status + "," + counter.get(status));
                    fileWriter.append(NEW_LINE_SEPARATOR);
                    if (status.equalsIgnoreCase("UNEXECUTED")) {
                        unexecutedCount += counter.get(status);
                    } else {
                        executionCount += counter.get(status);
                    }

                }
            }
            totalExecutionCount += executionCount;
            totalUnexecutedCount += unexecutedCount;

            fileWriter.append(NEW_LINE_SEPARATOR);
        }

        fileWriter.append(NEW_LINE_SEPARATOR);
        fileWriter.append("TOTAL CYCLES:" + "," + cycles.size());
        fileWriter.append(NEW_LINE_SEPARATOR);
        fileWriter.append("TOTAL EXECUTIONS:" + "," + totalExecutionCount);
        fileWriter.append(NEW_LINE_SEPARATOR);
        fileWriter.append("TOTAL ASSIGNED:" + "," + (totalUnexecutedCount + totalExecutionCount));

        System.out.println("CSV file was created successfully !!!");
    } catch (Exception e) {
        System.out.println("Error in CsvFileWriter !!!");
        e.printStackTrace();
    } finally {
        try {
            fileWriter.flush();
            fileWriter.close();
        } catch (IOException e) {
            System.out.println("Error while flushing/closing fileWriter !!!");
            e.printStackTrace();
        }
    }

}