List of usage examples for java.io FileInputStream read
public int read() throws IOException
From source file:ByteReader.java
public static void main(String[] arguments) { try {/*from ww w . j a v a 2 s. co m*/ FileInputStream file = new FileInputStream("class.dat"); boolean eof = false; int count = 0; while (!eof) { int input = file.read(); System.out.print(input + " "); if (input == -1) eof = true; else count++; } file.close(); System.out.println("\nBytes read: " + count); } catch (IOException e) { System.out.println("Error - " + e.toString()); } }
From source file:Main.java
public static void main(String[] args) throws IOException { FileInputStream fis = new FileInputStream(FileDescriptor.in); // skip bytes from file input stream fis.skip(4);//from w ww .j a v a2 s .c om // read bytes from this stream int i = fis.read(); // converts integer to character char c = (char) i; System.out.print("Character read: " + c); }
From source file:Copy.java
public static void main(String[] args) throws Exception { FileInputStream fis = null; FileOutputStream fos = null;/*from w w w .j ava 2s . c o m*/ fis = new FileInputStream(args[0]); fos = new FileOutputStream(args[1]); int byte_; while ((byte_ = fis.read()) != -1) fos.write(byte_); }
From source file:Main.java
public static void main(String[] args) throws IOException { FileInputStream fis = new FileInputStream(new File("C://test.txt")); // skip bytes from file input stream fis.skip(4);/*from ww w . j a va2s. c o m*/ // read bytes from this stream int i = fis.read(); // converts integer to character char c = (char) i; System.out.print("Character read: " + c); }
From source file:FileDeflater.java
public static void main(String[] args) throws Exception { FileInputStream fin = new FileInputStream("a.dat"); FileOutputStream fout = new FileOutputStream("b.dat"); DeflaterOutputStream dos = new DeflaterOutputStream(fout); for (int c = fin.read(); c != -1; c = fin.read()) { dos.write(c);/*from ww w . j a v a 2s . com*/ } dos.close(); fin.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { Properties prop = new Properties(); prop.put("Chapter Count", "200"); prop.put("Tutorial Count", "15"); prop.put("tutorial", "java2s.com"); // create a output and input as a xml file FileOutputStream fos = new FileOutputStream("properties.xml"); FileInputStream fis = new FileInputStream("properties.xml"); prop.storeToXML(fos, "Properties Example", "ISO 8859"); while (fis.available() > 0) { System.out.print((char) fis.read()); }//from w w w . j a v a 2 s . co m }
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);/*from w ww. j a va 2s . 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:MainClass.java
public static void main(String[] args) throws IOException { String outputFile = "new.zip"; // Default to maximum compression int level = 9; int start = 1; FileOutputStream fout = new FileOutputStream(outputFile); ZipOutputStream zout = new ZipOutputStream(fout); zout.setLevel(level);//w w w .java2s .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) { String s = "from java2s.com!"; try {/*from w w w.jav a 2 s . c o m*/ OutputStream os = new FileOutputStream("test.txt"); OutputStreamWriter writer = new OutputStreamWriter(os); FileInputStream in = new FileInputStream("test.txt"); writer.write(s, 0, 5); writer.flush(); for (int i = 0; i < 5; i++) { System.out.print((char) in.read()); } writer.close(); in.close(); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) { String s = "from java2s.com!"; try {/*from w w w. j av a 2s . co m*/ OutputStream os = new FileOutputStream("test.txt"); OutputStreamWriter writer = new OutputStreamWriter(os, Charset.defaultCharset().newEncoder()); FileInputStream in = new FileInputStream("test.txt"); writer.write(s, 0, 5); writer.flush(); for (int i = 0; i < 5; i++) { System.out.print((char) in.read()); } writer.close(); in.close(); } catch (Exception ex) { ex.printStackTrace(); } }