List of usage examples for java.io File File
public File(URI uri)
From source file:Main.java
public static void main(String[] argv) throws Exception { File f = new File("C:\\test.txt"); FileReader fr = new FileReader(f); BufferedReader br = new BufferedReader(fr); StringBuffer sb = new StringBuffer(); String eachLine = br.readLine(); while (eachLine != null) { sb.append(eachLine);//from w ww. j ava 2s . c o m sb.append("\n"); eachLine = br.readLine(); } System.out.println(sb.toString()); }
From source file:Main.java
public static void main(String[] args) { File fileObject = new File("person.ser"); try (ObjectInputStream ois = new ObjectInputStream(new FileInputStream(fileObject))) { Person p1 = (Person) ois.readObject(); Person p2 = (Person) ois.readObject(); Person p3 = (Person) ois.readObject(); System.out.println(p1);//from www .j a v a 2 s.com System.out.println(p2); System.out.println(p3); } catch (Exception e) { e.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) throws Exception { Document doc = Jsoup.parse(new File("t2.html"), "UTF-8"); doc.select("area#area1").after("<area id=\"newArea\" />"); System.out.println(doc.html()); }
From source file:Main.java
public static void main(String args[]) throws Exception { File file = new File("."); if (file.isDirectory()) { String[] files = file.list(); for (int i = 0; i < files.length; i++) System.out.println(files[i]); } else {/*from w w w. j av a 2s . co m*/ FileReader fr = new FileReader(file); BufferedReader in = new BufferedReader(fr); String line; while ((line = in.readLine()) != null) System.out.println(line); } }
From source file:Main.java
public static void main(String[] args) { File file = new File("xyz.txt"); Formatter fm = null;//from w w w . j av a 2s . c om try { // Create a Formatter that will write the output the file fm = new Formatter(file); // Formatting strings fm.format("%1$s, %2$s, and %3$s %n", "A", "B", "C"); fm.format("%3$s, %2$s, and %1$s %n", "A", "B", "C"); // Format more text here... } catch (FileNotFoundException e) { e.printStackTrace(); } finally { if (fm != null) { fm.close(); } } }
From source file:Main.java
public static void main(String[] args) throws Exception { File file = new File("C:/ReadFile.txt"); FileInputStream fin = new FileInputStream(file); BufferedInputStream bin = new BufferedInputStream(fin); while (bin.available() > 0) { System.out.println((char) bin.read()); }//from w w w.java 2s. c o m bin.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { ZipFile zipFile = new ZipFile(new File("testfile.zip"), ZipFile.OPEN_READ); ZipEntry entry = zipFile.getEntry("fileName"); }
From source file:Main.java
public static void main(String[] args) { final JFileChooser chooser = new JFileChooser(new File(".")) { public void approveSelection() { if (getSelectedFile().exists()) { super.approveSelection(); } else System.out.println("File doesn't exist"); }//from www . j a v a 2 s .c o m }; chooser.addActionListener(e -> System.out.println(e)); chooser.setSelectedFile(new File("something.txt")); int returnVal = chooser.showSaveDialog(null); if (returnVal == JFileChooser.APPROVE_OPTION) { System.out.println(chooser.getSelectedFile()); } }
From source file:Main.java
public static void main(String[] args) { String dirPath = "C:\\"; File dir = new File(dirPath); // Create a file filter to exclude any .SYS file FileFilter filter = file -> { if (file.isFile()) { String fileName = file.getName().toLowerCase(); if (fileName.endsWith(".sys")) { return false; }/*from w w w . j ava 2 s .c o m*/ } return true; }; File[] list = dir.listFiles(filter); for (File f : list) { if (f.isFile()) { System.out.println(f.getPath() + " (File)"); } else if (f.isDirectory()) { System.out.println(f.getPath() + " (Directory)"); } } }
From source file:Main.java
public static void main(String[] argv) throws Exception { JarFile jarfile = new JarFile(new File("filename.jar"), true, JarFile.OPEN_READ); JarEntry entry = jarfile.getJarEntry("fileName"); }