List of usage examples for java.io FileWriter FileWriter
public FileWriter(File file, Charset charset) throws IOException
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();/* w w w .j a v a 2 s .c o m*/ }
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 w w w . ja v a2 s . c om }
From source file:Main.java
public static void main(String[] argv) throws Exception { BufferedWriter out = new BufferedWriter(new FileWriter("filename", true)); out.write("aString"); out.close();//from w w w. j a v a 2s.c o m }
From source file:Main.java
public static void main(String[] args) throws Exception { File file = new File("user.txt"); FileWriter writer = new FileWriter(file, true); writer.write("username=java;password=secret" + System.getProperty("line.separator")); writer.flush();//from w w w . j a v a2 s . co m writer.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { String multilineString = "This is line 1\nthis is line 2\nthis is last line"; FileWriter fileWriter = new FileWriter("multiline.txt", true); BufferedWriter bufferedWriter = new BufferedWriter(fileWriter); bufferedWriter.write(multilineString + "\n"); bufferedWriter.flush();/*from w w w. j a va 2 s . c om*/ bufferedWriter.close(); fileWriter.close(); }
From source file:Main.java
public static void main(String args[]) throws Exception { PrintWriter pw = new PrintWriter(new FileWriter("logfile.txt", true)); timeStamp("File opened", pw); pw.close();//from w w w . jav a2 s . c om if (pw.checkError()) System.out.println("I/O error occurred."); }
From source file:Main.java
public static void main(String[] args) throws Exception { String filename = "fileName.txt"; String[] linesToWrite = new String[] { "a", "b" }; boolean appendToFile = true; PrintWriter pw = null;//from w w w.j ava2 s . c o m if (appendToFile) { pw = new PrintWriter(new FileWriter(filename, true)); } else { pw = new PrintWriter(new FileWriter(filename)); // pw = new PrintWriter(new FileWriter(filename, false)); } for (int i = 0; i < linesToWrite.length; i++) { pw.println(linesToWrite[i]); } pw.flush(); pw.close(); }
From source file:base64test.Base64Test.java
/** * @param args the command line arguments *///from www . j a v a 2 s .c o m public static void main(String[] args) { try { if (!Base64.isBase64(args[0])) { throw new Exception("Arg 1 is not a Base64 string!"); } else { String decodedBase64String = new String(Base64.decodeBase64(args[0])); File tempFile = File.createTempFile("base64Test", ".tmp"); tempFile.deleteOnExit(); FileWriter fw = new FileWriter(tempFile, false); PrintWriter pw = new PrintWriter(fw); pw.write(decodedBase64String); pw.close(); String fileType = getFileType(tempFile.toPath()); System.out.println(fileType); System.in.read(); } } catch (Exception e) { System.err.println(e.getMessage()); } }
From source file:jsonparser.ToJSON.java
public static void main(String args[]) throws FileNotFoundException, IOException { String text_file = "C:/Users/Kevin/Documents/NetBeansProjects/JsonParser/src/jsonparser/sample.txt"; File file = new File(text_file); String s1, s2, s3;/* ww w . j av a 2 s .c o m*/ s1 = (String) FileUtils.readLines(file).get(0); String split1[] = s1.split("="); contact_id = split1[1]; s2 = (String) FileUtils.readLines(file).get(1); String split2[] = s2.split("="); confidence_level = Float.valueOf(split2[1]); s3 = (String) FileUtils.readLines(file).get(2); String split3[] = s3.split("="); if (split3[1].equals(" Found")) { is_matched = true; } else { is_matched = false; } System.out.println("Read from text file:"); System.out.println("contact_id =" + contact_id); System.out.println("confidence_level = " + confidence_level); System.out.println("is_matched = " + is_matched); FacialRecognition fr = new FacialRecognition(); fr.setContactID(contact_id); fr.setConfidenceLevel(confidence_level); fr.setIsMatched(is_matched); Gson gson = new GsonBuilder().setPrettyPrinting().create(); //convert java object to JSON format String json = gson.toJson(fr); //write JSON to a file try { //write converted json data to a file named "CountryGSON.json" FileWriter writer = new FileWriter( "C:/Users/Kevin/Documents/NetBeansProjects/JsonParser/src/jsonparser/test.json", true); writer.write("" + json + ",\n"); writer.close(); } catch (IOException e) { e.printStackTrace(); } //eventually need to change to send over back to client-side System.out.println(); System.out.println("Coverting strings into JSON..."); System.out.println(json); }
From source file:MyTerrierClass.java
public static void main(String[] args) throws InterruptedException, IOException { System.gc();//from w ww . ja v a2 s . co m System.setProperty("terrier.home", "/home/manan/Downloads/terrier-4.0"); System.setProperty("terrier.etc", "/home/manan/Downloads/terrier-4.0/etc"); System.setProperty("terrier.setup", "/home/manan/Downloads/terrier-4.0/etc/terrier.properties"); bw = new BufferedWriter(new FileWriter("/home/manan/terrier_trials/myOutput.txt", false)); bw.write("#######OUTPUT#######"); List<String> cl = new ArrayList<>(); cl.add("/home/manan/wiki-small/"); SimpleFileCollection sf = new SimpleFileCollection(cl, true); print("sf list size b4 indexing:" + sf.getFileList().size()); Indexer indexer = new BlockIndexer("/home/manan/terrier_trials/", ".trial"); indexer.index(new Collection[] { sf }); print("sf list size after indexing:" + sf.getFileList().size()); sf.reset(); //get document reader Reader reader = sf.next().getReader(); //print all tokens Tokeniser tokeniser = Tokeniser.getTokeniser(); TokenStream ts = tokeniser.tokenise(reader); while (ts.hasNext()) { System.out.println(ts.next()); } // Index index = Index.createIndex(); // // Manager queryingManager = new Manager(index); // // String query = "name quick"; // SearchRequest srq = queryingManager.newSearchRequest("queryID0", query); // srq.addMatchingModel("Matching", "PL2"); // queryingManager.runPreProcessing(srq); // queryingManager.runMatching(srq); // queryingManager.runPostProcessing(srq); // queryingManager.runPostFilters(srq); // ResultSet rs = srq.getResultSet(); // for(int each : rs.getDocids()) // System.out.println("docids: "+ each); // Index index = Index.createIndex(); // Lexicon<String> lex = index.getLexicon(); // print("lex number of entries: "+lex.numberOfEntries()); // String myTerm = "name"; // LexiconEntry le = lex.getLexiconEntry(myTerm); // if(le!=null) // { // print(myTerm+" in number of docs: "+le.getDocumentFrequency()); // print(myTerm+" occurance times: "+le.getFrequency()); // } // else // { // print(myTerm+" not found"); // } // Index index = Index.createIndex(); // BitPostingIndex inv = (BitPostingIndex) index.getInvertedIndex(); // MetaIndex meta = index.getMetaIndex(); // Lexicon<String> lex = index.getLexicon(); // LexiconEntry le = lex.getLexiconEntry( "name" ); // IterablePosting postings = inv.getPostings((BitIndexPointer) le); // while (postings.next() != IterablePosting.EOL) { // String docno = meta.getItem("docno", postings.getId()); // System.out.println(docno + " with frequency " + postings.getFrequency()); // } bw.close(); }