Results 1 to 4 of 4
  1. #1
    jurka is offline Member
    Join Date
    Jul 2008
    Posts
    67
    Rep Power
    0

    Default Right use of file reading ?

    Java Code:
    		FileInputStream in = new FileInputStream("C:\\andmed.txt");
    		
    		final int BUFFER_SIZE = 8;
    		int off = 0;
    		int actualBytesRead = 0;
    		byte[] buffer = new byte[BUFFER_SIZE];
    		
    		while ((actualBytesRead = in.read(buffer, 0, BUFFER_SIZE)) != -1) {
    			off += actualBytesRead -1;
    			System.out.println(Arrays.toString(buffer));
    		}

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default

    What are you trying to do?
    What kind of data is in the andmed.txt file? character?

    What is being printed? Is it what you want?

  3. #3
    jurka is offline Member
    Join Date
    Jul 2008
    Posts
    67
    Rep Power
    0

    Default

    Reading binary and text files. I mostly used for reading files like this
    Java Code:
    		while ((byte = in.read()) != -1) {
    			System.out.println(byte);
    		}
    But i though this is waste of resources, reading byte by byte

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default

    Then read them a bunch at a time as your were:
    in.read(buffer, 0, BUFFER_SIZE)

    What are you trying to do?

Similar Threads

  1. Reading a properties file
    By peiceonly in forum New To Java
    Replies: 7
    Last Post: 05-06-2010, 05:17 PM
  2. Reading a file
    By mew in forum New To Java
    Replies: 2
    Last Post: 12-30-2007, 12:23 PM
  3. Reading text file
    By Lennon-Guru in forum New To Java
    Replies: 1
    Last Post: 12-15-2007, 11:38 PM
  4. Reading a file for use
    By peachyco in forum New To Java
    Replies: 2
    Last Post: 11-27-2007, 03:49 AM
  5. Reading from a file
    By leebee in forum New To Java
    Replies: 1
    Last Post: 07-23-2007, 12:02 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •