List of usage examples for java.io FileWriter write
public void write(int c) throws IOException
From source file:de.mpg.escidoc.services.edoc.CreatePurgeScript2.java
/** * @param args//from w w w . j a va2s . co m */ public static void main(String[] args) throws Exception { CORESERVICES_URL = PropertyReader.getProperty("escidoc.framework_access.framework.url"); String userHandle = AdminHelper.loginUser(args[0], args[1]); logger.info("Querying core-services..."); HttpClient httpClient = new HttpClient(); String filter = "<param><filter name=\"http://escidoc.de/core/01/structural-relations/context\">" + IMPORT_CONTEXT + "</filter><filter name=\"/properties/public-status\">released</filter><order-by>http://escidoc.de/core/01/properties/creation-date</order-by><limit>0</limit></param>"; PostMethod postMethod = new PostMethod(CORESERVICES_URL + "/ir/items/filter"); postMethod.setRequestHeader("Cookie", "escidocCookie=" + userHandle); postMethod.setRequestBody(filter); ProxyHelper.executeMethod(httpClient, postMethod); String response = postMethod.getResponseBodyAsString(); logger.info("...done!"); FileWriter xmlData = new FileWriter("xmlData.xml"); xmlData.write(response); xmlData.close(); //System.out.println(response); logger.info("Transforming result..."); XSLTTransform transform = new XSLTTransform(); File stylesheet = new File("src/main/resources/itemlist2purgescript.xslt"); FileOutputStream outputStream = new FileOutputStream("purge.sh"); transform.transform(response, stylesheet, outputStream); logger.info("...done!"); logger.info("Finished!"); }
From source file:Main.java
public static void main(String[] args) throws Exception { Class.forName("oracle.jdbc.driver.OracleDriver"); Connection conn = DriverManager.getConnection(url, username, password); PreparedStatement stmt = conn.prepareStatement("SELECT name, description, data FROM documents "); ResultSet resultSet = stmt.executeQuery(); while (resultSet.next()) { String name = resultSet.getString(1); String description = resultSet.getString(2); File data = new File("C:\\a.txt"); Reader reader = resultSet.getCharacterStream(3); FileWriter writer = new FileWriter(data); char[] buffer = new char[1]; while (reader.read(buffer) > 0) { writer.write(buffer); }//from w w w .ja v a 2s . c om writer.close(); } conn.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { Connection conn = getConnection(); Statement st = conn.createStatement(); st.executeUpdate("create table survey (Id int, b CLOB);"); PreparedStatement pstmt = conn.prepareStatement("INSERT INTO survey VALUES(1,?)"); File file = new File("c:/Java_Dev/data.txt"); FileReader reader = new FileReader(file); pstmt.setCharacterStream(1, reader); pstmt.execute();/*from w ww .j a va 2 s . co m*/ ResultSet resultSet = pstmt.executeQuery("select b from survey "); File data = new File("C:\\a.txt"); Reader dataReader = resultSet.getCharacterStream(1); FileWriter writer = new FileWriter(data); char[] buffer = new char[1]; while (dataReader.read(buffer) > 0) { writer.write(buffer); } writer.close(); reader.close(); st.close(); conn.close(); }
From source file:com.doculibre.constellio.utils.resources.WriteResourceBundleUtils.java
@SuppressWarnings("unchecked") public static void main(String[] args) throws Exception { File binDir = ClasspathUtils.getClassesDir(); File projectDir = binDir.getParentFile(); File sourceDir = new File(projectDir, "source"); String defaultLanguage;/*from w ww . j a v a2s. com*/ String otherLanguage; if (args.length > 0) { defaultLanguage = args[0]; otherLanguage = args[1]; } else { defaultLanguage = Locale.ENGLISH.getLanguage(); otherLanguage = Locale.FRENCH.getLanguage(); } List<File> propertiesFiles = (List<File>) FileUtils.listFiles(sourceDir, new String[] { "properties" }, true); for (File propertiesFile : propertiesFiles) { File propertiesDir = propertiesFile.getParentFile(); String propertiesNameWoutSuffix = StringUtils.substringBefore(propertiesFile.getName(), "_"); propertiesNameWoutSuffix = StringUtils.substringBefore(propertiesNameWoutSuffix, ".properties"); String noLanguageFileName = propertiesNameWoutSuffix + ".properties"; String defaultLanguageFileName = propertiesNameWoutSuffix + "_" + defaultLanguage + ".properties"; String otherLanguageFileName = propertiesNameWoutSuffix + "_" + otherLanguage + ".properties"; File noLanguageFile = new File(propertiesDir, noLanguageFileName); File defaultLanguageFile = new File(propertiesDir, defaultLanguageFileName); File otherLanguageFile = new File(propertiesDir, otherLanguageFileName); if (defaultLanguageFile.exists() && otherLanguageFile.exists() && !noLanguageFile.exists()) { System.out.println(defaultLanguageFile.getPath() + " > " + noLanguageFileName); System.out.println(defaultLanguageFile.getPath() + " > empty file"); defaultLanguageFile.renameTo(noLanguageFile); FileWriter defaultLanguageEmptyFileWriter = new FileWriter(defaultLanguageFile); defaultLanguageEmptyFileWriter.write(""); IOUtils.closeQuietly(defaultLanguageEmptyFileWriter); } } }
From source file:SentiWordNetDemoCode.java
public static void main(String[] args) throws IOException { if (args.length < 2) { System.err.println("Usage: java SentiWordNetDemoCode <pathToSentiWordNetFile>"); return;/*from w w w.j ava2s. c o m*/ } String pathToSWN = args[0]; SentiWordNetDemoCode sentiwordnet = new SentiWordNetDemoCode(pathToSWN); JSONObject js = new JSONObject(sentiwordnet.dictionary); FileWriter csv = null; try { csv = new FileWriter(args[1]); csv.write(js.toJSONString()); System.out.println("error"); } catch (Exception e) { e.printStackTrace(); } finally { if (csv != null) { csv.close(); } } // System.out.println("good#a "+sentiwordnet.extract("good", "a")); // System.out.println("bad#a "+sentiwordnet.extract("bad", "a")); // System.out.println("blue#a "+sentiwordnet.extract("blue", "a")); // System.out.println("blue#n "+sentiwordnet.extract("blue", "n")); }
From source file:com.dianping.wed.cache.redis.util.TestDataUtil.java
public static void main(String[] args) { // ????/*from w w w . ja va2 s .c o m*/ //&method=incr¶meterTypes=com.dianping.wed.cache.redis.dto.WeddingRedisKeyDTO¶meters={"category":"justtest","params":["1","2"]} List<String> opList = new ArrayList<String>(opAndKey.keySet()); for (int i = 0; i < 1000; i++) { int index = RandomUtils.nextInt(opList.size()); String op = opList.get(index); String key = opAndKey.get(op); StringBuilder result = new StringBuilder(); int params = buildTestUrl(result, op, key); String fileName = "/Users/Bob/Desktop/data/data-" + params + ".csv"; try { //kuka.txt //kuka.txt FileWriter writer = new FileWriter(fileName, true); writer.write(result.toString()); writer.close(); } catch (IOException e) { e.printStackTrace(); } } System.out.println("done"); }
From source file:contractEditor.contractHOST4.java
public static void main(String[] args) { JSONObject obj = new JSONObject(); obj.put("name", "HOST4"); obj.put("context", "VM-deployment"); //obj.put("Context", new Integer); HashMap serviceDescription = new HashMap(); serviceDescription.put("location", "France"); serviceDescription.put("certificate", "true"); serviceDescription.put("volume", "100_GB"); serviceDescription.put("price", "3_euro"); obj.put("serviceDescription", serviceDescription); HashMap gauranteeTerm = new HashMap(); gauranteeTerm.put("availability", "more_98_percentage"); obj.put("gauranteeTerm", gauranteeTerm); //Constraint1 ArrayList creationConstraint1 = new ArrayList(); ArrayList totalConstraint = new ArrayList(); totalConstraint.add(creationConstraint1); obj.put("creationConstraint", totalConstraint); try {// ww w . j a v a2 s . co m FileWriter file = new FileWriter("confSP" + File.separator + "Host4.json"); file.write(obj.toJSONString()); file.flush(); file.close(); } catch (IOException e) { e.printStackTrace(); } System.out.print(obj); /* JSONParser parser = new JSONParser(); try { Object obj2 = parser.parse(new FileReader("confSP\\confHost1.json")); JSONObject jsonObject = (JSONObject) obj2; HashMap serviceDescription2=(HashMap) jsonObject.get("serviceDescription"); method.printHashMap(serviceDescription2); HashMap gauranteeTerm2=(HashMap) jsonObject.get("gauranteeTerm"); method.printHashMap(gauranteeTerm2); ArrayList creationConstraint=(ArrayList) jsonObject.get("creationConstraint"); method.printArrayList(creationConstraint); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (ParseException e) { e.printStackTrace(); } */ }
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;// w ww . j a v 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:json.WriteToFile.java
public static void main(String[] args) { JSONObject countryObj = new JSONObject(); countryObj.put("Name", "Kenya"); countryObj.put("Population", new Integer(430000000)); JSONArray listOfCounties = new JSONArray(); listOfCounties.add("Nairobi"); listOfCounties.add("Kiambu"); listOfCounties.add("Murang'a"); countryObj.put("Counties", listOfCounties); try {//from w ww . j a v a 2 s . c om //writing to file File file = new File("/home/mars/Desktop/JsonExample1.json"); file.createNewFile(); FileWriter fw = new FileWriter(file); System.out.println("Writing JSON object to file"); System.out.println("---------------------------"); System.out.println(countryObj); fw.write(countryObj + ""); fw.flush(); fw.close(); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.mysql.servlet.NewClass.java
public static void main(String[] args) { JSONObject headerFile = new JSONObject(); JSONArray listOfAttrs = new JSONArray(); listOfAttrs.add("id" + ""); listOfAttrs.add("name" + ""); listOfAttrs.add("age" + ""); listOfAttrs.add("salary" + ""); listOfAttrs.add("grade" + ""); headerFile.put("Employee", listOfAttrs); try {/*from w w w . j av a2 s .com*/ // Writing to a file File file = new File("D:\\Employees.json"); file.createNewFile(); FileWriter fileWriter = new FileWriter(file); System.out.println("Writing JSON object to file"); System.out.println("-----------------------"); System.out.print(headerFile); fileWriter.write(headerFile.toJSONString()); fileWriter.flush(); fileWriter.close(); } catch (IOException e) { e.printStackTrace(); } }