Results 1 to 4 of 4

Thread: Reading data from file

  1. #1

    Thread Starter
    Member
    Join Date
    Apr 2001
    Location
    Los Angeles
    Posts
    45

    Reading data from file

    I am trying to read a certain ammount of bytes from a file and write it to anouther file. The certain amount of bytes in not always the same. Here the number of bytes is stored in NewSize which is a long. The name of the new file is in Name, string. An error occurs saying '.class' is expected and point to buffer[] on this line:

    c = in.read(buffer[], y, (int) NewSize - 1);

    It seems to think buffer[] is a class??

    Also the compiler does not like anything to do with the out, out.close() expects an extra ')' at the end, the out.write(buffer[].length); causes a 'cannot resolve symbol?

    --------
    int x, c;
    int y = 0;
    byte buffer[];

    //All this is in a try/catch

    InputStream in = new FileInputStream(FilePath);
    c = in.read(buffer[], y, (int) NewSize - 1);
    if (c != -1) {
    OutputStream out = new FileOutputStream(Name);
    out.write(buffer[].length);
    out.close();
    }

  2. #2

  3. #3

    Thread Starter
    Member
    Join Date
    Apr 2001
    Location
    Los Angeles
    Posts
    45
    Yes thank you, your stream copier helped, and also I found that when you create a byte array, byte buffer[], you also have to say what size of you want the array, byte buffer[] = new byte[10];

    then in the rest of the code you just refer to buffer, not buffer[].

  4. #4

Posting Permissions

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



Click Here to Expand Forum to Full Width