List of usage examples for java.io FileInputStream read
public int read() throws IOException
From source file:Main.java
public static void main(String[] args) throws IOException { int i = 0;/*from w ww . j av a 2 s . c om*/ // create new file input stream FileInputStream fis = new FileInputStream("C://test.txt"); // read till the end of the file while ((i = fis.read()) != -1) { // converts integer to character char c = (char) i; System.out.print(c); } }
From source file:Main.java
public static void main(String[] args) throws Exception { FileInputStream fis = new FileInputStream("main.java"); int i = 0;//from w ww . j av a2 s . co m int count = 0; while ((i = fis.read()) != -1) { if (i != -1) { System.out.printf("%02X ", i); count++; } if (count == 16) { System.out.println(""); count = 0; } } fis.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { OutputStream os = new FileOutputStream("C://test.txt"); FilterOutputStream fos = new FilterOutputStream(os); // writes buffer to the output stream fos.write(65);/*from w w w. ja va2s . c o m*/ // forces byte contents to written out to the stream fos.flush(); // create input streams FileInputStream fis = new FileInputStream("C://test.txt"); // get byte from the file int i = fis.read(); // convert integer to character char c = (char) i; System.out.print("Character read: " + c); fos.close(); fis.close(); }
From source file:Main.java
public static void main(String[] args) throws IOException { int i = 0;/*from www . ja v a2 s . c o m*/ FileInputStream fis = new FileInputStream("C://test.txt"); // read till the end of the stream while ((i = fis.read()) != -1) { // available bytes int available = fis.available(); // convert integer to character char c = (char) i; System.out.println("Available: " + available); System.out.println("Read: " + c); } }
From source file:Main.java
public static void main(String[] args) throws IOException { int i = 0;/*from w w w. jav a 2 s . c om*/ FileInputStream fis = new FileInputStream("C://test.txt"); // read till the end of the file while ((i = fis.read()) != -1) { // get file channel FileChannel fc = fis.getChannel(); // get channel position long pos = fc.position(); char c = (char) i; System.out.println("No of bytes read: " + pos); System.out.println("Char read: " + c); } }
From source file:Main.java
public static void main(String[] args) throws IOException { byte[] b = { 65, 66, 67, 68, 69 }; int i = 0;/*from w w w. j av a 2 s . c om*/ FileOutputStream fos = new FileOutputStream("C://test.txt"); fos.write(b); // flushes the content to the underlying stream fos.flush(); // create new file input stream FileInputStream fis = new FileInputStream("C://test.txt"); // read till the end of the file while ((i = fis.read()) != -1) { // convert integer to character char c = (char) i; System.out.print(c); } }
From source file:Main.java
public static void main(String[] args) throws Exception { File file = new File("C:/String.txt"); FileInputStream fin = new FileInputStream(file); int ch;/*from ww w .java 2s . c o m*/ // skip first 10 bytes fin.skip(10); while ((ch = fin.read()) != -1) { System.out.print((char) ch); } }
From source file:Main.java
public static void main(String[] args) throws IOException { byte b = 66;//from w w w .ja v a 2s. c om int i = 0; FileOutputStream fos = new FileOutputStream("C://test.txt", true); fos.write(b); fos.flush(); FileInputStream fis = new FileInputStream("C://test.txt"); // read till the end of the file while ((i = fis.read()) != -1) { // convert integer to character char c = (char) i; System.out.print(c); } }
From source file:Main.java
public static void main(String[] args) throws IOException { byte b = 66;//from w w w. j a v a 2 s. c om int i = 0; FileOutputStream fos = new FileOutputStream("C://test.txt"); fos.write(b); fos.flush(); FileInputStream fis = new FileInputStream("C://test.txt"); // read till the end of the file while ((i = fis.read()) != -1) { // convert integer to character char c = (char) i; System.out.print(c); } }
From source file:Main.java
public static void main(String[] args) throws IOException { byte b = 66;//from w ww . j av a 2 s . co m int i = 0; FileOutputStream fos = new FileOutputStream(new File("C://test1.txt"), true); fos.write(b); fos.flush(); FileInputStream fis = new FileInputStream("C://test.txt"); // read till the end of the file while ((i = fis.read()) != -1) { // convert integer to character char c = (char) i; System.out.print(c); } fos.close(); fis.close(); }