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:freightKt.KTFreight_v3.java

private static void writeRunInfo() {
    File file = new File(OUTPUT_DIR + "#RunInformation.txt");
    try {//from  w  w  w . j av a 2 s .  co  m
        FileWriter writer = new FileWriter(file); //Neuer File (berschreibt im Zweifel den alten - der jedoch nicht existieren drfte!

        writer.write("##Inputfiles:" + System.getProperty("line.separator"));
        writer.write("Net: \t \t" + NETFILE + System.getProperty("line.separator"));
        writer.write("Carrier:  \t" + CARRIERFILE + System.getProperty("line.separator"));
        writer.write("VehType: \t" + VEHTYPEFILE + System.getProperty("line.separator"));
        writer.write("Algorithm: \t" + ALGORITHMFILE + System.getProperty("line.separator"));
        writer.write("Toll: \t" + TOLL_NAME + System.getProperty("line.separator"));
        writer.write("LowEmissionZone: \t" + LEZ_NAME + System.getProperty("line.separator"));

        writer.write(System.getProperty("line.separator"));
        writer.write("##Run Settings:" + System.getProperty("line.separator"));
        writer.write("addingCongestion: \t" + addingCongestion + System.getProperty("line.separator"));
        writer.write("addingToll: \t \t" + addingToll + System.getProperty("line.separator"));
        writer.write("usingUCC: \t \t" + usingUCC + System.getProperty("line.separator"));
        writer.write("runMatsim: \t \t" + runMatsim + System.getProperty("line.separator"));
        writer.write(
                "Last Matsim Iteration: \t" + LAST_MATSIM_ITERATION + System.getProperty("line.separator"));
        writer.write("Max Jsprit Iteration: \t" + MAX_JSPRIT_ITERATION + System.getProperty("line.separator"));
        writer.write("Number of Runs: \t" + NU_OF_TOTAL_RUNS + System.getProperty("line.separator"));

        writer.flush();
        writer.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
    System.out.println("Datei: " + file + " geschrieben.");
}

From source file:com.endlessloopsoftware.ego.client.graph.GraphData.java

public static void writeCoordinates(File dataFile) throws IOException {
    VisualizationViewer<Vertex, Edge> vv = GraphRenderer.getVv();
    Layout<Vertex, Edge> layout = vv.getGraphLayout();
    Graph g = layout.getGraph();/*  w ww.j a  va 2  s . co  m*/

    FileWriter fw = new FileWriter(dataFile);

    @SuppressWarnings("unchecked")
    Collection<Vertex> verts = g.getVertices();
    for (Vertex v : verts) {

        String nodeLabel = GraphRenderer.getGraphSettings().getNodeLabel(v);

        Point2D pt = layout.transform(v);
        String line = ("\"" + nodeLabel + "\"," + pt.getX() + "," + pt.getY() + "\n");
        System.out.print(line);
        fw.write(line);
    }

    fw.close();
}

From source file:freightKt.KTFreight_v3.java

/**
 * Prft ob alle Services auch in den geplanten Touren vorkommen, d.h., ob sie auhc tatschslcih geplant wurden.
 * Falls nicht: log.Error und Ausgabe einer Datei: "#UnassignedServices.txt" mit den Service-Ids.
 * @param carriers//from  w  w  w.j a  v a  2  s .  c  o  m
 */

//TODO: Ausgabe der Anassigned Services in Run-Verzeichnis und dafrin der bersicht nur eine Nennung der Anzahl unassignedServices je Run 
//TODO: multiassigned analog.
private static void checkServiceAssignment(Carriers carriers) {
    for (Carrier c : carriers.getCarriers().values()) {
        ArrayList<CarrierService> assignedServices = new ArrayList<CarrierService>();
        ArrayList<CarrierService> multiassignedServices = new ArrayList<CarrierService>();
        ArrayList<CarrierService> unassignedServices = new ArrayList<CarrierService>();

        System.out.println("### Carrier: " + c.getId());
        //Erfasse alle einer Tour zugehrigen (-> stattfindenden) Services 
        for (ScheduledTour tour : c.getSelectedPlan().getScheduledTours()) {
            for (TourElement te : tour.getTour().getTourElements()) {
                if (te instanceof ServiceActivity) {
                    CarrierService assigService = ((ServiceActivity) te).getService();
                    if (!assignedServices.contains(assigService)) {
                        assignedServices.add(assigService);
                        System.out.println("Assigned Service: " + assignedServices.toString());
                    } else {
                        multiassignedServices.add(assigService);
                        log.error("Service wurde von dem Carrier " + c.getId().toString()
                                + " bereits angefahren: " + assigService.getId().toString());
                    }
                }
            }
        }

        //Nun prfe, ob alle definierten Service zugeordnet wurden
        for (CarrierService service : c.getServices()) {
            System.out.println("Service to Check: " + service.toString());
            if (!assignedServices.contains(service)) {
                System.out.println("Service not assigned: " + service.toString());
                unassignedServices.add(service);
                log.error("Service wird von Carrier " + c.getId().toString() + " NICHT bedient: "
                        + service.getId().toString());
            } else {
                System.out.println("Service was assigned: " + service.toString());
            }
        }

        //Schreibe die mehrfach eingeplanten Services in Datei
        if (!multiassignedServices.isEmpty()) {
            try {
                FileWriter writer = new FileWriter(new File(TEMP_DIR + "#MultiAssignedServices.txt"), true);
                writer.write("#### Multi-assigned Services of Carrier: " + c.getId().toString()
                        + System.getProperty("line.separator"));
                for (CarrierService s : multiassignedServices) {
                    writer.write(s.getId().toString() + System.getProperty("line.separator"));
                }
                writer.flush();
                writer.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        //Schreibe die nicht eingeplanten Services in Datei
        if (!unassignedServices.isEmpty()) {
            try {
                FileWriter writer = new FileWriter(new File(TEMP_DIR + "#UnassignedServices.txt"), true);
                writer.write("#### Unassigned Services of Carrier: " + c.getId().toString()
                        + System.getProperty("line.separator"));
                for (CarrierService s : unassignedServices) {
                    writer.write(s.getId().toString() + System.getProperty("line.separator"));
                }
                writer.flush();
                writer.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    } //for(carriers)

}

From source file:edu.kit.dama.util.SystemUtils.java

/**
 * Generate the chgrp script for Unix systems.
 *
 * @return The full path to the chgrp script.
 *
 * @throws IOException If the generation fails.
 *///from   w  w  w  .ja v  a2  s  .  c  o  m
private static String generateChgrpScript() throws IOException {
    String scriptFile;
    FileWriter fout = null;
    try {
        scriptFile = FilenameUtils.concat(System.getProperty("java.io.tmpdir"), "chgrpFolder.sh");
        fout = new FileWriter(scriptFile, false);
        StringBuilder b = new StringBuilder();
        b.append("#!/bin/sh\n");
        b.append("echo Changing ownership of $2 to $1\n");
        b.append("chgrp $1 $2 -R\n");
        LOGGER.debug("Writing script data to '{}'", scriptFile);
        fout.write(b.toString());
        fout.flush();
    } finally {
        if (fout != null) {
            try {
                fout.close();
            } catch (IOException ioe) {//ignore
            }
        }
    }
    return scriptFile;
}

From source file:edu.kit.dama.util.SystemUtils.java

/**
 * Generate the open script for Unix systems.
 *
 * @return The full path to the open script.
 *
 * @throws IOException If the generation fails.
 *///w  w  w. j  a  va  2s  .c o m
private static String generateOpenScript() throws IOException {
    String scriptFile;
    FileWriter fout = null;
    try {
        scriptFile = FilenameUtils.concat(System.getProperty("java.io.tmpdir"), "stickFolder.sh");
        fout = new FileWriter(scriptFile, false);
        StringBuilder b = new StringBuilder();
        b.append("#!/bin/sh\n");
        b.append("echo Changing access of $1 to 2770\n");
        b.append("chmod 2770 $1 -R\n");
        LOGGER.debug("Writing script data to '{}'", scriptFile);
        fout.write(b.toString());
        fout.flush();
    } finally {
        if (fout != null) {
            try {
                fout.close();
            } catch (IOException ioe) {//ignore
            }
        }
    }
    return scriptFile;
}

From source file:com.cisco.dbds.utils.tims.TIMS.java

/**
 * Generate tims xml file.//from  www  . java  2 s .c  om
 */
public static void generateTimsXMLFile() {
    try {
        String fileName = xmlFileName;
        File outFile = new File(fileName);
        FileWriter out = new FileWriter(outFile);
        out.write(xml);
        out.close();
        xml = "";
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:edu.kit.dama.transfer.client.types.TransferTask.java

/**
 * Writes a list of TransferTask entities in XML format into pFile
 *
 * @param pTasks The list of tasks to persist
 * @param pFile The file where the data will be written to
 *
 * @throws IOException If the file could not be written
 *//*from  w  ww .jav  a2  s .  c o m*/
public static void toXML(List<TransferTask> pTasks, File pFile) throws IOException {
    StringBuilder buffer = new StringBuilder();
    FileWriter writer = null;
    buffer.append("<transferTasks>\n");
    try {
        writer = new FileWriter(pFile);
        int cnt = 0;
        for (TransferTask task : pTasks) {
            buffer.append(task.toXml()).append("\n");
            cnt++;
            if (cnt % 100 == 0) {//flush buffer all 100 tasks
                writer.write(buffer.toString());
                writer.flush();
                buffer = new StringBuilder();
            }
        }
        writer.write(buffer.toString());
        writer.write("</transferTasks>\n");
        writer.flush();
    } finally {
        if (writer != null) {
            try {
                writer.close();
            } catch (IOException ioe) {
            }
        }
    }
}

From source file:com.sldeditor.test.unit.tool.vector.VectorToolTest.java

/**
 * Stream 2 file./*from   www  .  ja  v  a2s  .  com*/
 *
 * @param in the in
 * @return the file
 * @throws IOException Signals that an I/O exception has occurred.
 */
private static File stream2file(InputStream in) throws IOException {
    final File tempFile = File.createTempFile(PREFIX, SUFFIX);
    try (FileOutputStream out = new FileOutputStream(tempFile)) {
        IOUtils.copy(in, out);
    }

    // Update the font for the operating system
    String newFont = getFontForOS();
    if (newFont.compareToIgnoreCase(DEFAULT_FONT) != 0) {
        BufferedReader br = new BufferedReader(new FileReader(tempFile));
        try {
            StringBuilder sb = new StringBuilder();
            String line = br.readLine();

            while (line != null) {
                sb.append(line.replace(DEFAULT_FONT, newFont));
                sb.append("\n");
                line = br.readLine();
            }
            try {
                FileWriter fileWriter = new FileWriter(tempFile);
                fileWriter.write(sb.toString());
                fileWriter.flush();
                fileWriter.close();
            } catch (IOException e) {
                e.printStackTrace();
            }

        } finally {
            br.close();
        }
    }
    return tempFile;
}

From source file:au.org.ala.spatial.analysis.layers.LayerDistanceIndex.java

public static void put(Map<String, Double> newDistances) {
    FileWriter fw = null;
    try {//from w ww  .  j ava2s. c  o m
        //create distances file if it does not exist.
        File layerDistancesFile = new File(IntersectConfig.getAlaspatialOutputPath() + LAYER_DISTANCE_FILE);
        if (!layerDistancesFile.exists()) {
            fw = new FileWriter(layerDistancesFile);
            fw.close();
        }

        fw = new FileWriter(layerDistancesFile, true);
        for (String key : newDistances.keySet()) {
            fw.write(key + "=" + newDistances.get(key) + "\n");
        }
        fw.flush();
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
    } finally {
        if (fw != null) {
            try {
                fw.close();
            } catch (Exception e) {
                logger.error(e.getMessage(), e);
            }
        }
    }

}

From source file:au.org.ala.layers.grid.GridClassBuilder.java

private static void copyHeaderAsInt(String src, String dst) {
    BufferedReader br = null;//from w ww  .j a  v a  2  s .c o  m
    FileWriter fw = null;
    try {
        br = new BufferedReader(new FileReader(src));
        fw = new FileWriter(dst);
        String line;
        while ((line = br.readLine()) != null) {
            if (line.startsWith("DataType=")) {
                fw.write("DataType=INT\n");
            } else {
                fw.write(line);
                fw.write("\n");
            }
        }
        fw.flush();
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
    } finally {
        if (br != null) {
            try {
                br.close();
            } catch (Exception e) {
                logger.error(e.getMessage(), e);
            }
        }
        if (fw != null) {
            try {
                fw.close();
            } catch (Exception e) {
                logger.error(e.getMessage(), e);
            }
        }
    }
}