List of usage examples for java.io FileWriter close
public void close() throws IOException
From source file:de.julielab.jtbd.TokenizerApplication.java
/** * writes an ArrayList of Strings to a file * * @param lines/*from ww w.java 2s . co m*/ * the ArrayList * @param outFile */ static void writeFile(final ArrayList<String> lines, final File outFile) { try { final FileWriter fw = new FileWriter(outFile); for (int i = 0; i < lines.size(); i++) fw.write(lines.get(i) + "\n"); fw.close(); } catch (final Exception e) { System.err.println("ERR: error writing file: " + outFile.toString()); e.printStackTrace(); System.exit(-1); } }
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();//from w w w .j a va2 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:com.cisco.dbds.utils.tims.TIMS.java
/** * Generate tims xml file.//w w w. ja v a2 s .co m */ 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:de.nrw.hbz.deepzoomer.fileUtil.FileUtil.java
/** * Method appends a String to File/*w w w . j a v a 2 s . c om*/ * @param fileName * @param contentString * @return */ public static String appendStringToResultFile(String fileName, String contentString) { FileWriter fw = null; try { inputFile = new File(Configuration.getResultDirPath() + fileName); fw = new FileWriter(inputFile, true); log.info(Configuration.getResultDirPath()); BufferedWriter bw = new BufferedWriter(fw); bw.append(contentString); bw.flush(); } catch (IOException ioExc) { log.error(ioExc); } finally { if (fw != null) { try { fw.close(); } catch (IOException ioExc) { log.error(ioExc); } } } log.info("File-Size, Ergebnis: " + inputFile.length()); return inputFile.getName(); }
From source file:gov.nasa.ensemble.common.io.FileUtilities.java
/** * Creates a file in the platform's working directory. * //from www .j ava 2s . c o m * @param relativeFilename * @param ins * @return boolean * @throws IOException */ public static boolean createFileInWorkingDirectory(String relativeFilename, InputStream ins) throws IOException { Location instanceLocation = Platform.getInstanceLocation(); if (instanceLocation == null || !instanceLocation.isSet()) { Logger logger = Logger.getLogger(FileUtilities.class); logger.warn("cannot create file '" + relativeFilename + "' because platform does not have a working directory."); return false; } else { File cacheFile = new File(instanceLocation.getURL().getFile() + File.separator + relativeFilename); // if cache file already exists, remove it because we are about to // overwrite it if (cacheFile.exists()) { cacheFile.delete(); } cacheFile.getParentFile().mkdirs(); cacheFile.createNewFile(); BufferedReader reader = new BufferedReader(new InputStreamReader(ins)); FileWriter writer = new FileWriter(cacheFile); String line = reader.readLine(); while (line != null) { writer.write(line); writer.write("\n"); line = reader.readLine(); } writer.flush(); writer.close(); return true; } }
From source file:mt.LengthDistribution.java
public static void WriteLengthdistroFile(ArrayList<File> AllMovies, XYSeries counterseries, int framenumber) { try {//from ww w . j av a2 s . c o m File ratesfile = new File(AllMovies.get(0).getParentFile() + "//" + "Length-Distribution At T " + " = " + framenumber + ".txt"); if (framenumber == 0) ratesfile = new File(AllMovies.get(0).getParentFile() + "//" + "Mean Length-Distribution" + ".txt"); FileWriter fw = new FileWriter(ratesfile); BufferedWriter bw = new BufferedWriter(fw); bw.write("\tLength(real units) \tCount\n"); for (int index = 0; index < counterseries.getItems().size(); ++index) { double Count = counterseries.getX(index).doubleValue(); double Length = counterseries.getY(index).doubleValue(); bw.write("\t" + Length + "\t" + "\t" + Count + "\t" + "\n"); } bw.close(); fw.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:com.fbartnitzek.tasteemall.data.csv.CsvFileWriter.java
public static String writeFile(String[] headers, List<List<String>> entries, File file) { FileWriter fileWriter = null; CSVPrinter csvFilePrinter = null;/*w w w .j ava2 s. co m*/ String msg = null; try { fileWriter = new FileWriter(file); //initialize FileWriter object csvFilePrinter = new CSVPrinter(fileWriter, CSV_FORMAT_RFC4180); //initialize CSVPrinter object csvFilePrinter.printRecord(Arrays.asList(headers)); //Create CSV file header //Write a new student object list to the CSV file for (List<String> dataEntry : entries) { csvFilePrinter.printRecord(dataEntry); } } catch (Exception e) { e.printStackTrace(); msg = "Error in CsvFileWriter !!!"; } finally { try { if (fileWriter != null) { fileWriter.flush(); fileWriter.close(); } if (csvFilePrinter != null) { csvFilePrinter.close(); } } catch (IOException e) { e.printStackTrace(); msg = "Error while flushing/closing fileWriter/csvPrinter !!!"; } } return msg; }
From source file:jeplus.TRNSYSWinTools.java
/** * Write a Job Done marker, typically a file named 'job.done!' in the given folder * * @param dir The folder in which the marker is written * @param marker The marker file name. The file contains a string "Job done!" * @return Marker is written successfully or not *///ww w . j a v a 2s . c o m public static boolean writeJobDoneMarker(String dir, String marker) { try { FileWriter fw = new FileWriter(dir + (dir.endsWith(File.separator) ? "" : File.separator) + marker); fw.write("Job done!"); fw.close(); return true; } catch (Exception ex) { logger.error("Error creating " + dir + (dir.endsWith(File.separator) ? "" : File.separator) + marker, ex); } return false; }
From source file:ems.util.DataHandler.java
public static boolean csvDownload(File file, ObservableList<MyModelSimpleStringProperty> data) { StringBuilder sb = new StringBuilder(); try {/*from ww w. j a v a 2s .c o m*/ for (String data1 : Constants.REPORT_COLUMN_HEADERS) { sb.append(data1).append(","); } sb.setLength(sb.length() - 1); sb.append("\r\n"); for (MyModelSimpleStringProperty data1 : data) { sb.append(data1.getObj1()).append(",").append(data1.getObj2()).append(",").append(data1.getObj4()) .append(",").append(data1.getObj5()).append(",").append(data1.getObj6()).append(",") .append(data1.getObj7()).append(",").append(data1.getObj8()).append(",") .append(data1.getObj9()).append(",").append(data1.getObj10()).append(",") .append(data1.getObj11()); sb.append("\r\n"); } FileWriter fw = new FileWriter(file); BufferedWriter bw = new BufferedWriter(fw); bw.write(sb.toString()); bw.close(); fw.close(); return true; } catch (Exception e) { log.error(e.getMessage()); } return false; }
From source file:de.uzk.hki.da.sb.restfulService.FileUtil.java
/** * Method appends a String to File// ww w. j av a2 s. c o m * @param fileName * @param contentString * @return */ public static String appendStringToResultFile(String fileName, String contentString) { FileWriter fw = null; try { inputFile = new File(Configuration.getResultDirPath() + fileName); fw = new FileWriter(inputFile, true); log.info(Configuration.getResultDirPath()); BufferedWriter bw = new BufferedWriter(fw); bw.append(contentString); bw.flush(); bw.close(); } catch (IOException ioExc) { log.error(ioExc); } finally { if (fw != null) { try { fw.close(); } catch (IOException ioExc) { log.error(ioExc); } } } log.info("File-Size, Ergebnis: " + inputFile.length()); return inputFile.getName(); }