List of usage examples for java.io BufferedWriter BufferedWriter
public BufferedWriter(Writer out)
From source file:Test.java
public static void main(String[] args) throws Exception { SSLSocketFactory sslSocketFactory = (SSLSocketFactory) SSLSocketFactory .getDefault();//from w ww .j ava 2s. co m SSLSocket sslSocket = (SSLSocket) sslSocketFactory.createSocket( "localhost", 9999); InputStreamReader inputStreamReader = new InputStreamReader(System.in); BufferedReader bufferedReader = new BufferedReader(inputStreamReader); OutputStream outputStream = sslSocket.getOutputStream(); OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream); BufferedWriter bufferedwriter = new BufferedWriter(outputStreamWriter); String line = null; while ((line = bufferedReader.readLine()) != null) { bufferedwriter.write(line + '\n'); bufferedwriter.flush(); } }
From source file:de.tudarmstadt.ukp.dkpro.keyphrases.wikipediafilter.filter.util.FileFilter.java
public static void main(String[] args) throws IOException { Set<String> articles = new HashSet<String>(); articles.addAll(FileUtils.readLines(new File("target/wikipedia/articles.txt"))); BufferedWriter writer = new BufferedWriter(new FileWriter(new File("target/passwords.txt.filtered"))); for (String line : FileUtils.readLines(new File("target/passwords.txt"))) { if (articles.contains(line.split("\t")[0].toLowerCase())) { writer.write(line);/* ww w . j a v a 2 s . c o m*/ writer.newLine(); } writer.close(); } }
From source file:com.idega.util.Stripper.java
public static void main(String[] args) { // Stripper stripper1 = new Stripper(); if (args.length != 2) { System.err.println("Auli. tt a hafa tvo parametra me essu, innskr og tskr"); return;//from ww w .ja v a 2s . co m } BufferedReader in = null; BufferedWriter out = null; try { in = new BufferedReader(new FileReader(args[0])); } catch (java.io.FileNotFoundException e) { System.err.println("Auli. Error : " + e.toString()); return; } try { out = new BufferedWriter(new FileWriter(args[1])); } catch (java.io.IOException e) { System.err.println("Auli. Error : " + e.toString()); IOUtils.closeQuietly(in); return; } try { String input = in.readLine(); int count = 0; while (input != null) { int index = input.indexOf("\\CVS\\"); if (index > -1) { System.out.println("Skipping : " + input); count++; } else { out.write(input); out.newLine(); } input = in.readLine(); } System.out.println("Skipped : " + count); } catch (java.io.IOException e) { System.err.println("Error reading or writing file : " + e.toString()); } try { in.close(); out.close(); } catch (java.io.IOException e) { System.err.println("Error closing files : " + e.toString()); } }
From source file:PCC.java
/** * @param args the command line arguments * @throws java.io.IOException// ww w. j a v a 2s .c o m */ public static void main(String[] args) throws IOException { // TODO code application logic here PearsonsCorrelation corel = new PearsonsCorrelation(); PCC method = new PCC(); ArrayList<String> name = new ArrayList<>(); Multimap<String, String> genes = ArrayListMultimap.create(); BufferedWriter bw = new BufferedWriter(new FileWriter(args[1])); BufferedReader br = new BufferedReader(new FileReader(args[0])); String str; while ((str = br.readLine()) != null) { String[] a = str.split("\t"); name.add(a[0]); for (int i = 1; i < a.length; i++) { genes.put(a[0], a[i]); } } for (String key : genes.keySet()) { double[] first = new double[genes.get(key).size()]; int element1 = 0; for (String value : genes.get(key)) { double d = Double.parseDouble(value); first[element1] = d; element1++; } for (String key1 : genes.keySet()) { if (!key.equals(key1)) { double[] second = new double[genes.get(key1).size()]; int element2 = 0; for (String value : genes.get(key1)) { double d = Double.parseDouble(value); second[element2] = d; element2++; } double corrlation = corel.correlation(first, second); if (corrlation > 0.5) { bw.write(key + "\t" + key1 + "\t" + corrlation + "\t" + method.pvalue(corrlation, second.length) + "\n"); } } } } br.close(); bw.close(); }
From source file:ASCII2NATIVE.java
public static void main(String[] args) { File f = new File("c:\\mydb.script"); File f2 = new File("c:\\mydb3.script"); if (f.exists() && f.isFile()) { // convert param-file BufferedReader br = null; StringBuffer sb = new StringBuffer(); String line;//w w w . j a va 2 s .c o m try { br = new BufferedReader(new InputStreamReader(new FileInputStream(f), "JISAutoDetect")); while ((line = br.readLine()) != null) { System.out.println(ascii2Native(line)); sb.append(ascii2Native(line)).append(";\n");//.append(";\n\r") } BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(f2), "utf-8")); out.append(sb.toString()); out.flush(); out.close(); } catch (FileNotFoundException e) { System.err.println("file not found - " + f); } catch (IOException e) { System.err.println("read error - " + f); } finally { try { if (br != null) br.close(); } catch (Exception e) { } } } else { // // convert param-data // System.out.print(ascii2native(args[i])); // if (i + 1 < args.length) // System.out.print(' '); } }
From source file:json_csv.JSON2CSV.java
public static void main(String myHelpers[]) { // These code snippets use an open-source library. http://unirest.io/java ObjectMapper mapper = new ObjectMapper(); JSON2CSV run = new JSON2CSV(); try {/*from w ww. j a v a 2s . c o m*/ run.ibw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("ingredient.csv"), "UTF-8")); run.rbw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("recipe.csv"), "UTF-8")); run.cbw = new BufferedWriter( new OutputStreamWriter(new FileOutputStream("cuisineRecipe.csv"), "UTF-8")); for (int i = 0; i < 100; i++) { // These code snippets use an open-source library. http://unirest.io/java HttpResponse<JsonNode> response = Unirest.get( "https://spoonacular-recipe-food-nutrition-v1.p.mashape.com/recipes/random?limitLicense=false&number=100") .header("X-Mashape-Key", "dkK9bOKEkNmshOLDuw9rHq59F0Twp1fvyxcjsn99AoUm6XvMfC") .header("Accept", "application/json").asJson(); // retrieve the parsed JSONObject from the response JSONObject myObj = response.getBody().getObject(); JSONArray results = myObj.getJSONArray("recipes"); run.parseRecipe(results); run.printRecipeToCSV(); run.printCuisineLookupTable(run.recipes); } run.rbw.flush(); run.rbw.close(); run.ibw.flush(); run.ibw.close(); run.cbw.flush(); run.cbw.close(); } catch (UnirestException ue) { ue.printStackTrace(); } catch (JSONException e) { e.printStackTrace(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:com.bright.utils.rmDuplicateLines.java
public static void main(String args) { File monfile = new File(args); Set<String> userIdSet = new LinkedHashSet<String>(); if (monfile.isFile() && monfile.getName().endsWith(".txt")) { try {//from ww w . j ava 2 s . c o m List<String> content = FileUtils.readLines(monfile, Charset.forName("UTF-8")); userIdSet.addAll(content); Iterator<String> itr = userIdSet.iterator(); StringBuffer output = new StringBuffer(); while (itr.hasNext()) { output.append(itr.next() + System.getProperty("line.separator")); } BufferedWriter out = new BufferedWriter(new FileWriter(monfile)); String outText = output.toString(); out.write(outText); out.close(); } catch (IOException e) { e.printStackTrace(); } } }
From source file:com.idega.util.FileLocalizer.java
public static void main(String[] args) { if (args.length != 2) { System.err.println("Wimp. I need two parameters, input file og directory and output file"); System.err.println("Usage java FileLocalizer input output"); return;//www.j av a 2 s . c o m } File in = null; BufferedWriter out = null; Properties props = new Properties(); try { in = new File(args[0]); } catch (Exception e) { System.err.println("Auli. Error : " + e.toString()); return; } try { out = new BufferedWriter(new FileWriter(args[1])); } catch (java.io.IOException e) { System.err.println("Auli. Error : " + e.toString()); return; } try { findRecursive(in, props); props.list(new PrintWriter(out)); } catch (Exception e) { System.err.println("Error reading or writing file : " + e.toString()); } try { out.close(); } catch (java.io.IOException e) { System.err.println("Error closing files : " + e.toString()); } }
From source file:com.cisco.dbds.utils.configfilehandler.FeatureFileRead_Testcase.java
/** * The main method.//from w ww.j a v a 2s.c o m * * @param args the arguments * @throws SocketException the socket exception * @throws IOException Signals that an I/O exception has occurred. */ public static void main(String args[]) throws SocketException, IOException { if (!rfile.exists()) { rfile.createNewFile(); } fw = new FileWriter(rfile.getAbsoluteFile()); bw = new BufferedWriter(fw); File dir = new File("C:\\TIMS"); String[] extensions = new String[] { "feature" }; System.out.println( "Getting all .feature files in " + dir.getCanonicalPath() + " including those in subdirectories"); List<File> files = (List<File>) FileUtils.listFiles(dir, extensions, true); for (File file : files) { System.out.println("file: " + file.getCanonicalPath()); readFeature(file.getCanonicalPath()); } bw.close(); }
From source file:cc.redberry.core.performance.StableSort.java
/** * @param args the command line arguments */// w w w.j a v a2 s.c om public static void main(String[] args) { try { //burn JVM BitsStreamGenerator bitsStreamGenerator = new Well19937c(); for (int i = 0; i < 1000; ++i) nextArray(1000, bitsStreamGenerator); System.out.println("!"); BufferedWriter timMeanOut = new BufferedWriter( new FileWriter("/home/stas/Projects/stableSort/timMean.dat")); BufferedWriter insertionMeanOut = new BufferedWriter( new FileWriter("/home/stas/Projects/stableSort/insertionMean.dat")); BufferedWriter timMaxOut = new BufferedWriter( new FileWriter("/home/stas/Projects/stableSort/timMax.dat")); BufferedWriter insertionMaxOut = new BufferedWriter( new FileWriter("/home/stas/Projects/stableSort/insertionMax.dat")); BufferedWriter timSigOut = new BufferedWriter( new FileWriter("/home/stas/Projects/stableSort/timSig.dat")); BufferedWriter insertionSigOut = new BufferedWriter( new FileWriter("/home/stas/Projects/stableSort/insertionSig.dat")); DescriptiveStatistics timSort; DescriptiveStatistics insertionSort; int tryies = 200; int arrayLength = 0; for (; arrayLength < 1000; ++arrayLength) { int[] coSort = nextArray(arrayLength, bitsStreamGenerator); timSort = new DescriptiveStatistics(); insertionSort = new DescriptiveStatistics(); for (int i = 0; i < tryies; ++i) { int[] t1 = nextArray(arrayLength, bitsStreamGenerator); int[] t2 = t1.clone(); long start = System.currentTimeMillis(); ArraysUtils.timSort(t1, coSort); long stop = System.currentTimeMillis(); timSort.addValue(stop - start); start = System.currentTimeMillis(); ArraysUtils.insertionSort(t2, coSort); stop = System.currentTimeMillis(); insertionSort.addValue(stop - start); } timMeanOut.write(arrayLength + "\t" + timSort.getMean() + "\n"); insertionMeanOut.write(arrayLength + "\t" + insertionSort.getMean() + "\n"); timMaxOut.write(arrayLength + "\t" + timSort.getMax() + "\n"); insertionMaxOut.write(arrayLength + "\t" + insertionSort.getMax() + "\n"); timSigOut.write(arrayLength + "\t" + timSort.getStandardDeviation() + "\n"); insertionSigOut.write(arrayLength + "\t" + insertionSort.getStandardDeviation() + "\n"); } timMeanOut.close(); insertionMeanOut.close(); timMaxOut.close(); insertionMaxOut.close(); timSigOut.close(); insertionSigOut.close(); } catch (IOException ex) { Logger.getLogger(StableSort.class.getName()).log(Level.SEVERE, null, ex); } }