List of usage examples for java.io FileWriter FileWriter
public FileWriter(FileDescriptor fd)
From source file:com.tomgibara.cluster.CreateUniformCircles.java
public static void main(String[] args) throws IOException { UniformRandomGenerator gen = new UniformRandomGenerator(new JDKRandomGenerator()); FileWriter writer = new FileWriter("R/circles.txt"); int size = 400; try {/*from w w w .ja va 2s . com*/ for (int y = 4; y >= -4; y--) { for (int x = -4; x <= 4; x++) { writeCluster(gen, new double[] { x, y }, new double[] { 0.3, 0.3 }, size, writer); } } } finally { writer.close(); } }
From source file:com.di.bi.nextgen.installattribution.searchcountrycode.SearchCountryCode.java
public static void main(String[] args) throws Exception { Map<String, String> map = CSVReader(); List<String> miss = new ArrayList<>(); List<String[]> data = new ArrayList<>(); String csv = "infinity.csv"; CSVWriter writer = new CSVWriter(new FileWriter(csv)); List<String[]> outList = new ArrayList<>(); JSONArray arry = ReadJson();/* w w w .j a va 2 s .c o m*/ for (String key : map.keySet()) { String[] arr = key.split(";"); boolean isf = false; for (int i = 0; i < arry.length(); ++i) { JSONObject o = arry.getJSONObject(i); if (arr.length > 1) { if (o.keySet().contains(arr[1].toUpperCase())) { System.out.println("arr[]1" + arr[1]); System.out.println("o.keySet() " + o.keySet()); System.out.println(" bu " + o.keySet().contains(arr[1].toUpperCase())); JSONArray arryC = o.getJSONArray(arr[1].toUpperCase()); for (int j = 0; j < arryC.length(); ++j) { String[] tmp = { map.get(key) + "," + key + ";" + arryC.getString(j) }; outList.add(tmp); } isf = true; break; } } } if (!isf) { miss.add(key); isf = false; } } writer.writeAll(outList); writer.close(); System.out.println("Miissing" + miss); }
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 w w w . j a v a2 s .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:com.tomgibara.cluster.CreateGaussianCross.java
public static void main(String[] args) throws IOException { GaussianRandomGenerator gen = new GaussianRandomGenerator(new JDKRandomGenerator()); final double[] center = new double[] { 0, 0 }; int clusterSize = 300; FileWriter writer = new FileWriter("R/cross.txt"); try {/*from w ww .j a va 2s. com*/ writeCluster(gen, center, new double[] { 6, 1 }, clusterSize, writer); writeCluster(gen, center, new double[] { 1, 6 }, clusterSize, writer); } finally { writer.close(); } }
From source file:contractEditor.SPConfFileEditor.java
public static void main(String[] args) { JSONObject obj = new JSONObject(); ArrayList fileList = new ArrayList(); fileList.add("confSP" + File.separator + "HOST1.json"); fileList.add("confSP" + File.separator + "HOST2.json"); fileList.add("confSP" + File.separator + "HOST3.json"); fileList.add("confSP" + File.separator + "HOST4.json"); obj.put("contract_list_of_SP", fileList); try {//w ww .j av a2s . c o m FileWriter file = new FileWriter("confSP" + File.separator + "contractFileList.json"); file.write(obj.toJSONString()); file.flush(); file.close(); } catch (IOException e) { e.printStackTrace(); } System.out.print(obj); }
From source file:PCC.java
/** * @param args the command line arguments * @throws java.io.IOException//from w w w. j av a2 s . 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: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 w w .j a va 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: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;// w w w .java2s . c om } 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:eval.dataset.ParseWikiLog.java
public static void main(String[] ss) throws FileNotFoundException, ParserConfigurationException, IOException { FileInputStream fin = new FileInputStream("data/enwiki-20151201-pages-logging.xml.gz"); GzipCompressorInputStream gzIn = new GzipCompressorInputStream(fin); InputStreamReader reader = new InputStreamReader(gzIn); BufferedReader br = new BufferedReader(reader); PrintWriter pw = new PrintWriter(new FileWriter("data/user_page.txt")); pw.println(//from w ww. j av a 2 s. co m "#list of user names and pages that they have edited, deleted or created. These info are mined from logitems of enwiki-20150304-pages-logging.xml.gz"); TreeMap<String, Set<String>> userPageList = new TreeMap(); TreeSet<String> pageList = new TreeSet(); int counterEntry = 0; String currentUser = null; String currentPage = null; try { for (String line = br.readLine(); line != null; line = br.readLine()) { if (line.trim().equals("</logitem>")) { counterEntry++; if (currentUser != null && currentPage != null) { updateMap(userPageList, currentUser, currentPage); pw.println(currentUser + "\t" + currentPage); pageList.add(currentPage); } currentUser = null; currentPage = null; } else if (line.trim().startsWith("<username>")) { currentUser = line.trim().split(">")[1].split("<")[0].replace(" ", "_"); } else if (line.trim().startsWith("<logtitle>")) { String content = line.trim().split(">")[1].split("<")[0]; if (content.split(":").length == 1) { currentPage = content.replace(" ", "_"); } } } } catch (IOException ex) { Logger.getLogger(ParseWikiLog.class.getName()).log(Level.SEVERE, null, ex); } pw.println("#analysed " + counterEntry + " entries of wikipesia log file"); pw.println("#gathered a list of unique user of size " + userPageList.size()); pw.println("#gathered a list of pages of size " + pageList.size()); pw.close(); gzIn.close(); PrintWriter pwUser = new PrintWriter(new FileWriter("data/user_list_page_edited.txt")); pwUser.println( "#list of unique users and pages that they have edited, extracted from logitems of enwiki-20150304-pages-logging.xml.gz"); for (String user : userPageList.keySet()) { pwUser.print(user); Set<String> getList = userPageList.get(user); for (String page : getList) { pwUser.print("\t" + page); } pwUser.println(); } pwUser.close(); PrintWriter pwPage = new PrintWriter(new FileWriter("data/all_pages.txt")); pwPage.println("#list of the unique pages that are extracted from enwiki-20150304-pages-logging.xml.gz"); for (String page : pageList) { pwPage.println(page); } pwPage.close(); System.out.println("#analysed " + counterEntry + " entries of wikipesia log file"); System.out.println("#gathered a list of unique user of size " + userPageList.size()); System.out.println("#gathered a list of pages of size " + pageList.size()); }
From source file:com.cisco.dbds.utils.configfilehandler.FeatureFileRead_Testcase.java
/** * The main method.// ww w.j a va2 s . co 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(); }