List of usage examples for java.io BufferedWriter write
public void write(int c) throws IOException
From source file:com.diskoverorta.utils.JsonConvertor.java
public static void main(String[] args) throws IOException { JsonConvertor js = new JsonConvertor(); js.JsonConvertor();//from w w w . j av a 2s . com BufferedWriter bf = new BufferedWriter(new FileWriter("/home/serendio/jaroutput-json.txt")); bf.write(js.JsonConvertor()); bf.newLine(); bf.flush(); bf.close(); }
From source file:Main.java
public static void main(String args[]) throws Exception { String fullURL = args[0];/* www . j ava2 s . c om*/ URL u = new URL(fullURL); URLConnection conn = u.openConnection(); conn.setDoInput(true); OutputStream theControl = conn.getOutputStream(); BufferedWriter out = new BufferedWriter(new OutputStreamWriter(theControl)); for (int i = 1; i < args.length; i++) { out.write(args[i] + "\n"); } out.close(); InputStream theData = conn.getInputStream(); String contentType = conn.getContentType(); if (contentType.toLowerCase().startsWith("text")) { BufferedReader in = new BufferedReader(new InputStreamReader(theData)); String line; while ((line = in.readLine()) != null) { System.out.println(line); } } }
From source file:Main.java
public static void main(String args[]) throws Exception { String fullURL = args[0];//from w ww . j a v a2 s . c om URL u = new URL(fullURL); URLConnection conn = u.openConnection(); conn.setDoOutput(true); OutputStream theControl = conn.getOutputStream(); BufferedWriter out = new BufferedWriter(new OutputStreamWriter(theControl)); for (int i = 1; i < args.length; i++) { out.write(args[i] + "\n"); } out.close(); InputStream theData = conn.getInputStream(); String contentType = conn.getContentType(); if (contentType.toLowerCase().startsWith("text")) { BufferedReader in = new BufferedReader(new InputStreamReader(theData)); String line; while ((line = in.readLine()) != null) { System.out.println(line); } } }
From source file:edu.cmu.cs.lti.ark.fn.identification.training.ConvertAlphabetFile.java
public static void main(String[] args) throws Exception { final String alphabetFile = args[0]; final String modelFile = args[1]; final String outFile = args[2]; final String featureType = args[3]; final double threshold = args.length >= 5 ? Double.parseDouble(args[4].trim()) : DEFAULT_THRESHOLD; // read in map from feature id -> feature name final BiMap<Integer, String> featureNameById = readAlphabetFile(new File(alphabetFile)).inverse(); // read in parameter values final double[] parameters = TrainBatch.loadModel(modelFile); // write out list of (feature name, feature value) pairs final BufferedWriter output = Files.newWriter(new File(outFile), Charsets.UTF_8); try {//w w w . j a v a 2 s. co m output.write(String.format("%s\n", featureType)); for (int i : xrange(parameters.length)) { final double val = parameters[i]; if (Math.abs(val) <= threshold) continue; output.write(String.format("%s\t%s\n", featureNameById.get(i), val)); } } finally { closeQuietly(output); } }
From source file:GetDirectDownload.java
/** * @param args//from www . j a v a 2 s .c o m * @throws ParseException */ public static void main(final String[] args) throws ParseException { // you can either set the 2 strings above, or pass them in to this program if (args.length == 2) { USER_NAME = args[0]; API_KEY = args[1]; } // make sure the credentials got set if (USER_NAME.equals("<YOUR USER NAME>") || API_KEY.equals("<YOUR API KEY>")) { System.err.println( "You must either edit this example file and put in your username and apikey OR pass them in as program arguments"); System.exit(1); } final ApiCredentials credentials = new ApiCredentials(USER_NAME, API_KEY); final NZBMatrixApi api = new NZBMatrixApi(credentials); try { // makes the request to the nzbMatrixAPI for a direct download of a particular post id final DirectDownloadResponse directDownload = api.getDirectDownload(314694); // save the nzb file to disk final String fileName = directDownload.getSuggestedFileName(); final BufferedWriter out = new BufferedWriter(new FileWriter(fileName)); out.write(directDownload.getNzbFileContents()); out.close(); System.out.println("Nzb File Saved As: " + fileName); } catch (final ClientProtocolException e) { e.printStackTrace(); } catch (final IOException e) { e.printStackTrace(); } catch (final NZBMatrixApiException e) { 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 {// w ww . ja v a 2 s. c om 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:Main.java
public static void main(String[] args) throws Exception { URL url = new URL("http://www.google.com"); BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream())); BufferedWriter writer = new BufferedWriter(new FileWriter("data.html")); String line;/*from w ww.j ava 2s . c o m*/ while ((line = reader.readLine()) != null) { System.out.println(line); writer.write(line); writer.newLine(); } reader.close(); writer.close(); }
From source file:Main.java
public static void main(String[] argv) throws Exception { BufferedReader br = new BufferedReader(new FileReader("in.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("out.txt")); int i;/*from w w w . ja v a 2s . co m*/ do { i = br.read(); if (i != -1) { if (Character.isLowerCase((char) i)) bw.write(Character.toUpperCase((char) i)); else if (Character.isUpperCase((char) i)) bw.write(Character.toLowerCase((char) i)); else bw.write((char) i); } } while (i != -1); br.close(); bw.close(); }
From source file:com.newproject.ApacheHttp.java
public static void main(String[] args) throws Exception { CloseableHttpClient httpclient = HttpClients.createDefault(); String jsonFilePath = "/Users/vikasmohandoss/Documents/Cloud/test.txt"; String url = "http://www.sentiment140.com/api/bulkClassifyJson&appid=vm2446@columbia.edu"; JSONParser jsonParser = new JSONParser(); JSONObject jsonObject = new JSONObject(); URL obj = new URL(url); HttpURLConnection con = (HttpURLConnection) obj.openConnection(); try {/* w w w . ja v a 2 s .com*/ FileReader fileReader = new FileReader(jsonFilePath); jsonObject = (JSONObject) jsonParser.parse(fileReader); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (ParseException e) { e.printStackTrace(); } System.out.println(jsonObject.toString()); /*try { /*HttpGet httpGet = new HttpGet("http://httpbin.org/get"); CloseableHttpResponse response1 = httpclient.execute(httpGet); // The underlying HTTP connection is still held by the response object // to allow the response content to be streamed directly from the network socket. // In order to ensure correct deallocation of system resources // the user MUST call CloseableHttpResponse#close() from a finally clause. // Please note that if response content is not fully consumed the underlying // connection cannot be safely re-used and will be shut down and discarded // by the connection manager. try { System.out.println(response1.getStatusLine()); HttpEntity entity1 = response1.getEntity(); // do something useful with the response body // and ensure it is fully consumed EntityUtils.consume(entity1); } finally { response1.close(); } HttpPost httpPost = new HttpPost("http://httpbin.org/post"); List <NameValuePair> nvps = new ArrayList <NameValuePair>(); nvps.add(new BasicNameValuePair("username", "vip")); nvps.add(new BasicNameValuePair("password", "secret")); httpPost.setEntity(new UrlEncodedFormEntity(nvps)); CloseableHttpResponse response2 = httpclient.execute(httpPost); try { System.out.println(response2.getStatusLine()); HttpEntity entity2 = response2.getEntity(); // do something useful with the response body // and ensure it is fully consumed EntityUtils.consume(entity2); } finally { response2.close(); } } finally { httpclient.close(); }*/ try { HttpPost request = new HttpPost("http://www.sentiment140.com/api/bulkClassifyJson"); StringEntity params = new StringEntity(jsonObject.toString()); request.addHeader("content-type", "application/json"); request.setEntity(params); HttpResponse response = httpclient.execute(request); System.out.println(response.toString()); String result = EntityUtils.toString(response.getEntity()); System.out.println(result); try { File file = new File("/Users/vikasmohandoss/Documents/Cloud/sentiment.txt"); // if file doesnt exists, then create it if (!file.exists()) { file.createNewFile(); } FileWriter fw = new FileWriter(file.getAbsoluteFile()); BufferedWriter bw = new BufferedWriter(fw); bw.write(result); bw.close(); System.out.println("Done"); } catch (IOException e) { e.printStackTrace(); } // handle response here... } catch (Exception ex) { // handle exception here } finally { httpclient.close(); } }
From source file:net.semanticmetadata.lire.solr.AddImages.java
public static void main(String[] args) throws IOException, InterruptedException { BitSampling.readHashFunctions();//from w ww .ja va 2 s . c o m LinkedList<Thread> threads = new LinkedList<Thread>(); for (int j = 10; j < 21; j++) { final int tz = j; Thread t = new Thread() { @Override public void run() { try { List<File> files = FileUtils .getAllImageFiles(new File("D:\\DataSets\\WIPO-US\\jpg_us_trim\\" + tz), true); int count = 0; BufferedWriter br = new BufferedWriter(new FileWriter("add-us-" + tz + ".xml", false)); br.write("<add>\n"); for (Iterator<File> iterator = files.iterator(); iterator.hasNext();) { File file = iterator.next(); br.write(createAddDoc(file).toString()); count++; // if (count % 1000 == 0) System.out.print('.'); } br.write("</add>\n"); br.close(); } catch (IOException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } } }; t.start(); threads.add(t); } for (Iterator<Thread> iterator = threads.iterator(); iterator.hasNext();) { Thread next = iterator.next(); next.join(); } }