List of usage examples for java.io FileReader close
public void close() throws IOException
From source file:MainClass.java
public static void main(String args[]) { try {//ww w. ja v a2 s. c om FileReader fr = new FileReader(args[0]); BufferedReader br = new BufferedReader(fr); String s; while ((s = br.readLine()) != null) System.out.println(s); fr.close(); } catch (Exception e) { System.out.println("Exception: " + e); } }
From source file:MainClass.java
public static void main(String args[]) { try {// ww w . j a va 2s. c om FileReader fr = new FileReader(args[0]); FileWriter fw = new FileWriter(args[1]); int i; while ((i = fr.read()) != -1) { fw.write(i); } fw.close(); fr.close(); } catch (Exception e) { System.out.println("Exception: " + e); } }
From source file:FileCopy.java
public static void main(String args[]) throws Exception { FileReader fr = new FileReader(args[0]); // Create a file writer FileWriter fw = new FileWriter(args[1]); // Read and copy characters int i;/*from w w w . ja va 2 s . co m*/ while ((i = fr.read()) != -1) { fw.write(i); } fw.close(); fr.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { File file = new File("data.csv"); FileReader fr = new FileReader(file); LineNumberReader lnr = new LineNumberReader(fr); // lnr.setLineNumber(400); String line = ""; while ((line = lnr.readLine()) != null) { System.out.println("Line Number " + lnr.getLineNumber() + ": " + line); }/*w ww . j a v a2s .c o m*/ fr.close(); lnr.close(); }
From source file:com.github.artifactresolver.MavenDependencyDownloader.java
public static void main(String[] args) throws Exception { new MavenDependencyDownloader(); parseCommandLine(args);/*from w w w .j a va 2 s. c o m*/ RepositorySystemHelper repoSystemHelper = new RepositorySystemHelper(localRepo); dependencyResolver = new DependencyResolver(repoSystemHelper); if (artifacts.isEmpty()) { JSONParser jsonParser = new JSONParser(); FileReader fileReader = new FileReader(new File(dependencyFile)); JSONArray jsonArray = (JSONArray) jsonParser.parse(fileReader); fileReader.close(); for (Object obj : jsonArray) { JSONObject jsonObj = (JSONObject) obj; String groupId = (String) jsonObj.get("groupId"); String artifactId = (String) jsonObj.get("artifactId"); String classifier = (String) jsonObj.get("classifier"); String extension = (String) jsonObj.get("extension"); String version = (String) jsonObj.get("version"); DefaultArtifact artifact = new DefaultArtifact(groupId, artifactId, classifier, extension, version); dependencyResolver.downloadDependencyTree(artifact, javadoc, sources); } } else { for (DefaultArtifact artifact : artifacts) { dependencyResolver.downloadDependencyTree(artifact, javadoc, sources); } } log.info("Artifacts downloaded to \"{}\". Finished. Thank you.", localRepo); }
From source file:MainClass.java
public static void main(String args[]) throws IOException { // Write output to a file. FileWriter fout = new FileWriter("test.txt"); fout.write("2 3.4 5 6 7.4 9.1 10.5 done"); fout.close();/*from w w w . ja v a2s . co m*/ FileReader fin = new FileReader("Test.txt"); Scanner src = new Scanner(fin); // Read and sum numbers. while (src.hasNext()) { if (src.hasNextDouble()) { System.out.println(src.nextDouble()); } else { break; } } fin.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { File archivo = new File("c:/Java_Dev/run.bat"); FileReader fr = new FileReader(archivo); BufferedReader br = new BufferedReader(fr); Vector<String> lines = new Vector<String>(); String line;//from w ww . j ava 2 s . co m while ((line = br.readLine()) != null) { lines.add(line); } JOptionPane.showMessageDialog(null, new JScrollPane(new JList(lines))); fr.close(); }
From source file:MainClass.java
public static void main(String args[]) throws Exception { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTextField nameTextField = new JTextField(); frame.add(nameTextField, BorderLayout.NORTH); FileReader reader = null; try {//w w w. jav a 2 s .c o m reader = new FileReader("fileName.txt"); nameTextField.read(reader, "fileName.txt"); } catch (IOException exception) { System.err.println("Load oops"); exception.printStackTrace(); } finally { if (reader != null) { try { reader.close(); } catch (IOException exception) { System.err.println("Error closing reader"); exception.printStackTrace(); } } } frame.setSize(250, 100); frame.setVisible(true); }
From source file:LabelSampleLoadText.java
public static void main(String args[]) { JFrame frame = new JFrame("Label Focus Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new JPanel(new BorderLayout()); JLabel label = new JLabel("Name: "); label.setDisplayedMnemonic(KeyEvent.VK_N); JTextField textField = new JTextField(); label.setLabelFor(textField);/* w w w . j a va 2 s. c om*/ panel.add(label, BorderLayout.WEST); panel.add(textField, BorderLayout.CENTER); frame.add(panel, BorderLayout.NORTH); frame.add(new JButton("Somewhere Else"), BorderLayout.SOUTH); frame.setSize(250, 150); frame.setVisible(true); FileReader reader = null; try { String filename = "test.txt"; reader = new FileReader(filename); textField.read(reader, filename); } catch (IOException exception) { System.err.println("Load oops"); } finally { if (reader != null) { try { reader.close(); } catch (IOException exception) { System.err.println("Error closing reader"); exception.printStackTrace(); } } } }
From source file:CopyCharacters.java
public static void main(String[] args) throws IOException { FileReader inputStream = null; FileWriter outputStream = null; try {//from w w w . j a va2 s .co m inputStream = new FileReader("xanadu.txt"); outputStream = new FileWriter("characteroutput.txt"); int c; while ((c = inputStream.read()) != -1) { outputStream.write(c); } } finally { if (inputStream != null) { inputStream.close(); } if (outputStream != null) { outputStream.close(); } } }