List of usage examples for java.io FileWriter FileWriter
public FileWriter(FileDescriptor fd)
From source file:com.lunix.cheata.utils.file.FileManager.java
public static void WriteFile(String fileName, String string) { try {/* www . jav a 2 s .c o m*/ BufferedWriter writer = new BufferedWriter( new FileWriter(new File(getDir().getAbsolutePath(), fileName))); writer.write(string); writer.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.shazam.fork.summary.JsonSummarySerializer.java
@Override public void print(Summary summary) { FileWriter writer = null;//from w w w . ja v a 2 s. c om try { File summaryFile = fileManager.createSummaryFile(); writer = new FileWriter(summaryFile); gson.toJson(summary, writer); writer.flush(); } catch (IOException e) { logger.error("Could not serialize the summary.", e); } finally { closeQuietly(writer); } }
From source file:TheReplacements.java
public static void write(String fileName, String text) throws IOException { PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(fileName))); out.print(text);//from w w w. jav a 2 s. c om out.close(); }
From source file:TestMapObjInterface.java
public static boolean runTest(String file, String fsName, String cnaddress) { try {/* w ww .jav a2 s. com*/ long targetNumChunks = 2; FileWriter godot = new FileWriter(file); File monet = new File(file); godot.write("I'm waiting."); godot.flush(); while ((monet.length() / CHUNK_SIZE + 1) < targetNumChunks) { godot.write("I'm waiting."); } godot.flush(); godot.close(); ArrayList<String> chunks = getChunks(file, fsName, cnaddress); long fileChunks = (monet.length() / CHUNK_SIZE) + 1; if (fileChunks == chunks.size()) { return true; } else { System.out.print("expected " + fileChunks + " chunks, got " + chunks.size() + ": "); return false; } } catch (Exception e) { return false; } }
From source file:com.github.rvesse.airline.parser.aliases.TestAliases.java
public static void prepareConfig(File f, String... lines) throws IOException { FileWriter writer = new FileWriter(f); for (String line : lines) { writer.append(line);/* w w w. jav a 2 s.com*/ writer.append('\n'); } writer.close(); }
From source file:com.test.goeuro.csvGenerator.CSVFileGenerator.java
/** * * @param respondArray/*from w ww . jav a 2s .com*/ */ public void createCSVFileAndWriteData(JsonArray respondArray) throws FileNotFoundException, IOException { FileWriter fileWriter = null; CSVPrinter csvFilePrinter = null; CSVFormat csvFileFormat = CSVFormat.EXCEL.withRecordSeparator(NEW_LINE_SEPARATOR); try { System.out.println("generating CVS file ...."); fileWriter = new FileWriter(new File(Constants.FILE_NAME)); csvFilePrinter = new CSVPrinter(fileWriter, csvFileFormat); csvFilePrinter.printRecord(FILE_HEADER); for (JsonElement jsonElement : respondArray) { List apiRespondData = new ArrayList(); JsonObject jsonObject = jsonElement.getAsJsonObject(); apiRespondData.add(jsonObject.get(Constants._ID).getAsString()); apiRespondData.add(jsonObject.get(Constants.NAME).getAsString()); apiRespondData.add(jsonObject.get(Constants.TYPE).getAsString()); JsonObject inGeoPosObject = jsonObject.getAsJsonObject(Constants.GEO_POSITION); apiRespondData.add(inGeoPosObject.get(Constants.LATITUDE).getAsDouble()); apiRespondData.add(inGeoPosObject.get(Constants.LONGITUDE).getAsDouble()); csvFilePrinter.printRecord(apiRespondData); } System.out.println("CSV generated successfully"); } catch (FileNotFoundException fnfex) { Logger.getLogger(CSVFileGenerator.class.getName()).log(Level.SEVERE, null, fnfex); System.out.println("Error in Open csv file"); fnfex.printStackTrace(); } catch (IOException ioex) { Logger.getLogger(CSVFileGenerator.class.getName()).log(Level.SEVERE, null, ioex); System.out.println("Error in Open/Write CsvFileWriter!!!"); ioex.printStackTrace(); } finally { try { fileWriter.flush(); fileWriter.close(); csvFilePrinter.close(); } catch (IOException e) { System.out.println("Error while flushing/closing fileWriter/csvPrinter !!!"); e.printStackTrace(); } catch (Exception ex) { System.out.println("Error while flushing/closing fileWriter/csvPrinter !!!"); ex.printStackTrace(); } } }
From source file:com.linkedin.pinot.core.data.readers.CSVRecordReaderTest.java
@BeforeClass public void setUp() throws Exception { FileUtils.forceMkdir(TEMP_DIR);//w ww . jav a 2s. co m try (FileWriter fileWriter = new FileWriter(DATA_FILE); CSVPrinter csvPrinter = new CSVPrinter(fileWriter, CSVFormat.DEFAULT.withHeader(COLUMNS))) { for (Object[] record : RECORDS) { csvPrinter.printRecord(record[0], StringUtils.join((int[]) record[1], CSVRecordReaderConfig.DEFAULT_MULTI_VALUE_DELIMITER)); } } }
From source file:edu.msu.cme.rdp.readseq.utils.RmDupSeqs.java
public static void filterDuplicates(String inFile, String outFile, int length, boolean debug) throws IOException { HashMap<String, String> idSet = new HashMap<String, String>(); IndexedSeqReader reader = new IndexedSeqReader(new File(inFile)); BufferedWriter outWriter = new BufferedWriter(new FileWriter(new File(outFile))); Set<String> allseqIDset = reader.getSeqIdSet(); Sequence seq;//from w w w .ja va 2s . c om if (debug) { System.out.println("ID\tdescription" + "\tcontained_by_ID\tdescription"); } for (String id : allseqIDset) { seq = reader.readSeq(id); boolean dup = false; HashSet<String> tempdupSet = new HashSet<String>(); for (String exID : idSet.keySet()) { String exSeq = idSet.get(exID); if (exSeq.length() >= seq.getSeqString().length()) { if (exSeq.contains(seq.getSeqString())) { dup = true; if (debug) { Sequence temp = reader.readSeq(exID); System.out.println(id + "\t" + seq.getDesc() + "\t" + exID + "\t" + temp.getDesc()); } break; } } else if (seq.getSeqString().contains(exSeq)) { tempdupSet.add(exID); } } if (!dup) { idSet.put(id, seq.getSeqString()); } for (String dupid : tempdupSet) { idSet.remove(dupid); if (debug) { Sequence temp = reader.readSeq(dupid); System.out.println(dupid + "\t" + temp.getDesc() + "\t" + id + "\t" + seq.getDesc()); } } } // get the unique seq for (String id : idSet.keySet()) { seq = reader.readSeq(id); if (seq.getSeqString().length() >= length) { outWriter.write(">" + id + "\t" + seq.getDesc() + "\n" + seq.getSeqString() + "\n"); } } reader.close(); outWriter.close(); }
From source file:MyServlet.java
public void saveState() { FileWriter fileWriter = null; PrintWriter printWriter = null; try {// www . j a va2s.c om fileWriter = new FileWriter("InitDestroyCounter.initial"); printWriter = new PrintWriter(fileWriter); printWriter.println(count); printWriter.close(); return; } catch (IOException e) { } }
From source file:test.gov.nih.nci.system.web.client.ComputerClient.java
private static File marshall(Computer computer) throws IOException, XMLUtilityException { String namespacePrefix = "gme://caCORE.caCORE/3.2/"; String jaxbContextName = "gov.nih.nci.cacoresdk.domain.onetomany.bidirectional"; //Marshaller marshaller = new JAXBMarshaller(includeXmlDeclaration,jaxbContextName); // Use this constructor if you plan to pass the namespace prefix with each call instead Marshaller marshaller = new JAXBMarshaller(true, jaxbContextName, namespacePrefix); Unmarshaller unmarshaller = new JAXBUnmarshaller(true, jaxbContextName); XMLUtility myUtil = new XMLUtility(marshaller, unmarshaller); File myFile = new File("Computer.xml"); FileWriter myWriter = new FileWriter(myFile); myUtil.toXML(computer, myWriter);/*from www . j a v a2 s . c o m*/ myWriter.close(); return myFile; }