List of usage examples for java.io FileWriter close
public void close() throws IOException
From source file:com.me.edu.Servlet.ElasticSearch_Backup.java
public static String cleanStopWords(String inputText) { String[] stopwords = { "the", "-RRB-", "-LRB-", "a", "as", "able", "about", "WHEREAS", "above", "according", "accordingly", "across", "actually", "after", "afterwards", "again", "against", "aint", "all", "allow", "allows", "almost", "alone", "along", "already", "also", "although", "always", "am", "among", "amongst", "an", "and", "another", "any", "anybody", "anyhow", "anyone", "anything", "anyway", "anyways", "anywhere", "apart", "appear", "appreciate", "appropriate", "are", "arent", "around", "as", "aside", "ask", "asking", "associated", "at", "available", "away", "awfully", "be", "became", "because", "become", "becomes", "becoming", "been", "before", "beforehand", "behind", "being", "believe", "below", "beside", "besides", "best", "better", "between", "beyond", "both", "brief", "but", "by", "cmon", "cs", "came", "can", "cant", "cannot", "cant", "cause", "causes", "certain", "certainly", "changes", "clearly", "co", "com", "come", "comes", "concerning", "consequently", "consider", "considering", "contain", "containing", "contains", "corresponding", "could", "couldnt", "course", "currently", "definitely", "described", "despite", "did", "didnt", "different", "do", "does", "doesnt", "doing", "dont", "done", "down", "downwards", "during", "each", "edu", "eg", "eight", "either", "else", "elsewhere", "enough", "entirely", "especially", "et", "etc", "even", "ever", "every", "everybody", "everyone", "everything", "everywhere", "ex", "exactly", "example", "except", "far", "few", "ff", "fifth", "first", "five", "followed", "following", "follows", "for", "former", "formerly", "forth", "four", "from", "further", "furthermore", "get", "gets", "getting", "given", "gives", "go", "goes", "going", "gone", "got", "gotten", "greetings", "had", "hadnt", "happens", "hardly", "has", "hasnt", "have", "havent", "having", "he", "hes", "hello", "help", "hence", "her", "here", "heres", "hereafter", "hereby", "herein", "hereupon", "hers", "herself", "hi", "him", "himself", "his", "hither", "hopefully", "how", "howbeit", "however", "i", "id", "ill", "im", "ive", "ie", "if", "ignored", "immediate", "in", "inasmuch", "inc", "indeed", "indicate", "indicated", "indicates", "inner", "insofar", "instead", "into", "inward", "is", "isnt", "it", "itd", "itll", "its", "its", "itself", "just", "keep", "keeps", "kept", "know", "knows", "known", "last", "lately", "later", "latter", "latterly", "least", "less", "lest", "let", "lets", "like", "liked", "likely", "little", "look", "looking", "looks", "ltd", "mainly", "many", "may", "maybe", "me", "mean", "meanwhile", "merely", "might", "more", "moreover", "most", "mostly", "much", "must", "my", "myself", "name", "namely", "nd", "near", "nearly", "necessary", "need", "needs", "neither", "never", "nevertheless", "new", "next", "nine", "no", "nobody", "non", "none", "noone", "nor", "normally", "not", "nothing", "novel", "now", "nowhere", "obviously", "of", "off", "often", "oh", "ok", "okay", "old", "on", "once", "one", "ones", "only", "onto", "or", "other", "others", "otherwise", "ought", "our", "ours", "ourselves", "out", "outside", "over", "overall", "own", "particular", "particularly", "per", "perhaps", "placed", "please", "plus", "possible", "presumably", "probably", "provides", "que", "quite", "qv", "rather", "rd", "re", "really", "reasonably", "regarding", "regardless", "regards", "relatively", "respectively", "right", "said", "same", "saw", "say", "saying", "says", "second", "secondly", "see", "seeing", "seem", "seemed", "seeming", "seems", "seen", "self", "selves", "sensible", "sent", "serious", "seriously", "seven", "several", "shall", "she", "should", "shouldnt", "since", "six", "so", "some", "somebody", "somehow", "someone", "something", "sometime", "sometimes", "somewhat", "somewhere", "soon", "sorry", "specified", "specify", "specifying", "still", "sub", "such", "sup", "sure", "ts", "take", "taken", "tell", "tends", "th", "than", "thank", "thanks", "thanx", "that", "thats", "thats", "the", "their", "theirs", "them", "themselves", "then", "thence", "there", "theres", "thereafter", "thereby", "therefore", "therein", "theres", "thereupon", "these", "they", "theyd", "theyll", "theyre", "theyve", "think", "third", "this", "thorough", "thoroughly", "those", "though", "three", "through", "throughout", "thru", "thus", "to", "together", "too", "took", "toward", "towards", "tried", "tries", "truly", "try", "trying", "twice", "two", "un", "under", "unfortunately", "unless", "unlikely", "until", "unto", "up", "upon", "us", "use", "used", "useful", "uses", "using", "usually", "value", "various", "very", "via", "viz", "vs", "want", "wants", "was", "wasnt", "way", "we", "wed", "well", "were", "weve", "welcome", "well", "went", "were", "werent", "what", "whats", "whatever", "when", "whence", "whenever", "where", "wheres", "whereafter", "whereas", "whereby", "wherein", "whereupon", "wherever", "whether", "which", "while", "whither", "who", "whos", "whoever", "whole", "whom", "whose", "why", "will", "willing", "wish", "with", "within", "without", "wont", "wonder", "would", "would", "wouldnt", "yes", "yet", "you", "youd", "youll", "youre", "youve", "your", "yours", "yourself", "yourselves", "zero" }; List<String> wordsList = new ArrayList<String>(); //String tweet = "Feeling miserable with the cold? Here's WHAT you can do."; inputText = inputText.trim().replaceAll("\\s+", " "); System.out.println("After trim: " + inputText); //Get all the words Tokenize rather than spliting String[] words = inputText.split(" "); for (String word : words) { wordsList.add(word);//from w w w . j a v a2s.c om } System.out.println("After for loop: " + wordsList); //remove stop words here from the temp list for (int i = 0; i < wordsList.size(); i++) { // get the item as string for (int j = 0; j < stopwords.length; j++) { if (stopwords[j].contains(wordsList.get(i)) || stopwords[j].toUpperCase().contains(wordsList.get(i))) { wordsList.remove(i); } } } String cleanString = ""; for (String str : wordsList) { System.out.print(str + " "); cleanString = cleanString.replaceAll(",", ""); cleanString = cleanString + " " + str; } try { FileWriter file = new FileWriter("cleanDoc.txt"); file.write(cleanString.toString()); file.flush(); file.close(); } catch (IOException e) { e.printStackTrace(); } return cleanString; }
From source file:it.intecs.pisa.toolbox.util.URLReader.java
public static void writeURLContentToXML(String infoXmlFile, String fileName) throws Exception { try {//from ww w. j a v a2 s .c om String host = null; String url = null; int port = 0; Element infoXml = new DOMUtil().fileToDocument(new File(infoXmlFile)).getDocumentElement(); if (infoXml != null) { host = infoXml.getAttribute("newVersionHost"); url = infoXml.getAttribute("newVersionUrl"); String portStr = infoXml.getAttribute("newVersionPort"); Integer portInt = new Integer(portStr); port = portInt.intValue(); } String fileContent = (String) getURLContent(host, url, port); if (fileContent == null) return; fileContent = fileContent.substring(fileContent.indexOf("<"), fileContent.lastIndexOf(">") + 1); File newFile = new File(fileName); FileWriter fw = new FileWriter(newFile); fw.write(fileContent); fw.close(); } catch (Exception e) { e.printStackTrace(System.out); return; } }
From source file:gov.nih.nci.ncicb.tcga.dcc.common.util.FileUtil.java
/** * Writes the given content in the given file * * @param content the content to add/* w w w . j av a 2s . c o m*/ * @param file the file into which to write the content * @throws IOException */ public static void writeContentToFile(final String content, final File file) throws IOException { FileWriter fileWriter = null; try { fileWriter = new FileWriter(file); fileWriter.write(content); } finally { if (fileWriter != null) { fileWriter.flush(); fileWriter.close(); } } }
From source file:main.RankerOCR.java
/** * Write all the given text in a new line in a CSV file * <p>//from w ww . j ava2 s. c o m * @param f CSV file to write * @param c Separator charter * @param s Values to write */ private static void writeOutpuDocCsv(File f, char c, String[] s) { FileWriter w = null; try { w = new FileWriter(f, true); for (String txt : s) { w.append(txt + c); } w.append("\n\r"); } catch (IOException ex) { printFormated(ex.getLocalizedMessage()); System.exit(-34); } finally { try { w.close(); } catch (IOException ex) { printFormated(ex.getLocalizedMessage()); System.exit(-34); } } }
From source file:com.comcast.cats.service.util.YAMLUtils.java
public static synchronized <T> void saveAsYAML(String filePath, T objectToSave, Representer representer) throws FileNotFoundException { if (objectToSave != null) { Yaml yaml;/*w w w . j ava2s. c o m*/ FileWriter fw = null; if (representer == null) { yaml = new Yaml(); } else { yaml = new Yaml(representer); } try { File file = new File(filePath); file.createNewFile(); // create file if one does not exist. fw = new FileWriter(filePath); yaml.dump(objectToSave, fw); } catch (Exception e) { e.printStackTrace(); } finally { if (fw != null) { try { fw.close(); } catch (IOException e) { e.printStackTrace(); } } } } }
From source file:com.moss.appsnap.keeper.freedesktop.FreeDesktopAppHandler.java
public static void writeDesktopFile(String name, File location, File target) throws IOException { FileWriter writer = new FileWriter(location); writer.append("[Desktop Entry]\n"); writer.append("Type=Application\n"); writer.append("Name="); writer.append(name);// w ww . ja v a 2 s . c om writer.append("\n"); writer.append("Exec="); writer.append(SHELL); writer.append(" "); writer.append(target.getAbsolutePath()); writer.append("\n"); writer.flush(); writer.close(); }
From source file:com.qawaa.gui.EventWebScanGUI.java
/** * ??/* ww w .j a v a 2s . com*/ */ private static void setConsoleRight() { consoleRight = new JPopupMenu(); consoleRight.setBorderPainted(true); consoleRight.setPopupSize(new Dimension(105, 135)); JMenuItem clear = new JMenuItem(CONTEXT.getMessage("gobal.right.menu.clear", null, Locale.CHINA), KeyEvent.VK_L); JMenuItem copy = new JMenuItem(CONTEXT.getMessage("gobal.right.menu.copy", null, Locale.CHINA), KeyEvent.VK_C); JMenuItem cut = new JMenuItem(CONTEXT.getMessage("gobal.right.menu.cut", null, Locale.CHINA), KeyEvent.VK_X); JMenuItem font = new JMenuItem(CONTEXT.getMessage("gobal.right.menu.font", null, Locale.CHINA), KeyEvent.VK_F); JMenuItem choose = new JMenuItem(CONTEXT.getMessage("gobal.right.menu.choose", null, Locale.CHINA), KeyEvent.VK_O); JMenuItem saveas = new JMenuItem(CONTEXT.getMessage("gobal.right.menu.saveas", null, Locale.CHINA), KeyEvent.VK_S); consoleRight.add(clear); consoleRight.add(copy); consoleRight.add(cut); consoleRight.add(font); consoleRight.add(choose); consoleRight.add(saveas); clear.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { consolePane.setText(""); jConsole.clear(); } }); copy.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (consolePane.getText() != null && !consolePane.getText().trim().isEmpty()) { Clipboard clip = Toolkit.getDefaultToolkit().getSystemClipboard(); Transferable tText = new StringSelection(consolePane.getText()); clip.setContents(tText, null); } } }); cut.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (consolePane.getText() != null && !consolePane.getText().trim().isEmpty()) { Clipboard clip = Toolkit.getDefaultToolkit().getSystemClipboard(); Transferable tText = new StringSelection(consolePane.getText()); clip.setContents(tText, null); } consolePane.setText(""); jConsole.clear(); } }); saveas.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JFileChooser fileChooser = new JFileChooser(); int option = fileChooser.showSaveDialog(null); if (option == JFileChooser.APPROVE_OPTION) { File file = fileChooser.getSelectedFile(); try { if (file.exists() == false) { file.createNewFile(); } FileWriter writer = new FileWriter(file); char[] arry = consolePane.getText().toCharArray(); writer.write(arry); writer.flush(); writer.close(); LOG.info(CONTEXT.getMessage("gobal.right.menu.saveas.success", null, Locale.CHINA)); } catch (IOException ioe) { } } } }); }
From source file:Main.java
/** * Print out the spike trains so it can be analyzed by plotting software * @param file//from ww w .j a v a 2 s . c o m * @param array */ public static void print(File file, double[] array) { FileWriter fstream = null; BufferedWriter out = null; try { fstream = new FileWriter(file); out = new BufferedWriter(fstream); for (int i = 0; i < array.length; i++) { out.write(array[i] + "\t"); } } catch (IOException e) { e.printStackTrace(); } finally { if (out != null) { try { out.close(); } catch (IOException e) { e.printStackTrace(); } } if (fstream != null) { try { fstream.close(); } catch (IOException e) { e.printStackTrace(); } } } }
From source file:au.org.ala.spatial.analysis.layers.LayerDistanceIndex.java
public static void put(Map<String, Double> newDistances) { FileWriter fw = null; try {/*from ww w . j ava 2 s . com*/ //create distances file if it does not exist. File layerDistancesFile = new File(IntersectConfig.getAlaspatialOutputPath() + LAYER_DISTANCE_FILE); if (!layerDistancesFile.exists()) { fw = new FileWriter(layerDistancesFile); fw.close(); } fw = new FileWriter(layerDistancesFile, true); for (String key : newDistances.keySet()) { fw.write(key + "=" + newDistances.get(key) + "\n"); } fw.flush(); } catch (Exception e) { logger.error(e.getMessage(), e); } finally { if (fw != null) { try { fw.close(); } catch (Exception e) { logger.error(e.getMessage(), e); } } } }
From source file:cn.kk.exia.MangaDownloader.java
private static void appendUrl(final File downloaded, final String mangaUrl) throws IOException { final FileWriter f = new FileWriter(downloaded, true); f.write(mangaUrl);/* ww w .j av a2 s.c o m*/ f.write('\n'); f.close(); }