List of usage examples for java.io FileInputStream FileInputStream
public FileInputStream(FileDescriptor fdObj)
FileInputStream
by using the file descriptor fdObj
, which represents an existing connection to an actual file in the file system. From source file:Main.java
public static void main(String[] args) throws IOException { String outputFile = "new.zip"; int level = 9; int start = 1; FileOutputStream fout = new FileOutputStream(outputFile); ZipOutputStream zout = new ZipOutputStream(fout); zout.setLevel(level);// ww w . j a v a2 s . c o m for (int i = start; i < args.length; i++) { ZipEntry ze = new ZipEntry(args[i]); FileInputStream fin = new FileInputStream(args[i]); try { System.out.println("Compressing " + args[i]); zout.putNextEntry(ze); for (int c = fin.read(); c != -1; c = fin.read()) { zout.write(c); } } finally { fin.close(); } } zout.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setValidating(false);// w w w . java2 s. c o m DocumentBuilder db = dbf.newDocumentBuilder(); Document doc = db.parse(new FileInputStream(new File("input.xml"))); File OutputDOM = new File("out.txt"); FileOutputStream fostream = new FileOutputStream(OutputDOM); OutputStreamWriter oswriter = new OutputStreamWriter(fostream); BufferedWriter bwriter = new BufferedWriter(oswriter); if (!OutputDOM.exists()) { OutputDOM.createNewFile(); } visitRecursively(doc, bwriter); bwriter.close(); oswriter.close(); fostream.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { FileOutputStream out = new FileOutputStream("test.txt"); ObjectOutputStream oout = new ObjectOutputStream(out); oout.writeObject(new Example()); oout.flush();//from w ww. j ava 2 s. c o m oout.close(); ObjectInputStream ois = new ObjectInputStream(new FileInputStream("test.txt")); Example a = (Example) ois.readObject(); System.out.println(a.isDefault); System.out.println(a.string); ois.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { String s = "Hello World from java2s.com"; FileOutputStream out = new FileOutputStream("test.txt"); ObjectOutputStream oout = new ObjectOutputStream(out); // write something in the file oout.writeUnshared(s);//from w w w. j a v a 2s .co m oout.flush(); oout.close(); // create an ObjectInputStream for the file we created before ObjectInputStream ois = new ObjectInputStream(new FileInputStream("test.txt")); // read and print the unshared object System.out.println(ois.readUnshared()); ois.close(); }
From source file:MappedReader.java
public static void main(String[] args) throws Exception { if (args.length != 1) { System.out.println("argument: sourcefile"); System.exit(1);/*from ww w .ja v a 2 s. co m*/ } MappedByteBuffer in = new FileInputStream(args[0]).getChannel().map(FileChannel.MapMode.READ_ONLY, 0, LENGTH); int i = 0; while (i < LENGTH) System.out.print((char) in.get(i++)); System.out.println((char) in.get(i++)); }
From source file:Main.java
public static void main(String[] args) throws Exception { String s = "Hello World from java2s.com"; FileOutputStream out = new FileOutputStream("test.txt"); ObjectOutputStream oout = new ObjectOutputStream(out); // write something in the file oout.writeUTF(s);//from w ww. ja va 2 s .c om oout.flush(); oout.close(); // create an ObjectInputStream for the file we created before ObjectInputStream ois = new ObjectInputStream(new FileInputStream("test.txt")); // read and print the whole content byte[] b = new byte[13]; ois.readFully(b); String array = new String(b); System.out.println(array); ois.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { byte[] buffer = { 65, 66, 67, 68, 69 }; int i = 0;/*from w ww .ja v a 2s. c o m*/ OutputStream os = new FileOutputStream("C://test.txt"); FilterOutputStream fos = new FilterOutputStream(os); // writes buffer to the output stream fos.write(buffer); // forces byte contents to written out to the stream fos.flush(); // create input streams FileInputStream fis = new FileInputStream("C://test.txt"); while ((i = fis.read()) != -1) { // converts integer to the character char c = (char) i; System.out.println("Character read: " + c); } fos.close(); fis.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { String s = "Hello World from java2s.com"; FileOutputStream out = new FileOutputStream("test.txt"); ObjectOutputStream oout = new ObjectOutputStream(out); // write something in the file oout.writeUTF(s);// w w w . j av a2 s . c o m oout.flush(); oout.close(); // create an ObjectInputStream for the file we created before ObjectInputStream ois = new ObjectInputStream(new FileInputStream("test.txt")); // read and print from index 0 to 7 byte[] b = new byte[13]; ois.readFully(b, 0, 7); String array = new String(b); System.out.println(array); ois.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { byte b = 12;// www. j a v a2 s . c om FileOutputStream out = new FileOutputStream("test.txt"); ObjectOutputStream oout = new ObjectOutputStream(out); // write something in the file oout.writeByte(b); oout.writeByte(21); oout.flush(); oout.close(); // create an ObjectInputStream for the file we created before ObjectInputStream ois = new ObjectInputStream(new FileInputStream("test.txt")); // read and print a byte System.out.println((char) ois.readByte()); // read and print a byte System.out.println((char) ois.readByte()); ois.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { char b = 'F'; FileOutputStream out = new FileOutputStream("test.txt"); ObjectOutputStream oout = new ObjectOutputStream(out); // write something in the file oout.writeChar(b);// w w w. j ava 2s . c om oout.writeChar('A'); oout.flush(); oout.close(); // create an ObjectInputStream for the file we created before ObjectInputStream ois = new ObjectInputStream(new FileInputStream("test.txt")); // read and print a char System.out.println(ois.readChar()); // read and print a char System.out.println(ois.readChar()); ois.close(); }