/ Published in: Java
Expand |
Embed | Plain Text
import java.io.BufferedInputStream; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; /* * To change this template, choose Tools | Templates * and open the template in the editor. */ public class Main { /** * This method reads contents of a file and print it out */ byte[] buffer = new byte[1024]; try { //Construct the BufferedInputStream object int bytesRead = 0; //Keep reading from the file while there is any content //when the end of the stream has been reached, -1 is returned while (bufferedInput.available() != 0) { //Process the chunk of bytes read //in this case we just construct a String and print it out } ex.printStackTrace(); ex.printStackTrace(); } finally { //Close the BufferedInputStream try { if (bufferedInput != null) { bufferedInput.close(); } ex.printStackTrace(); } } } /** * @param args the command line arguments */ new Main().readFromFile("myFile.txt"); } }
You need to login to post a comment.
