fileSize help

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jonjon0688
    New Member
    • Mar 2008
    • 14

    #16
    yes it says use this method:

    public int countChars(Inpu tStream input) throws IOException
    {
    int count = 0;
    BufferedInputSt ream input2 = new BufferedInputSt ream(input);
    while(input2.re ad() != -1)
    {
    count++;
    }
    return count;
    }

    but how? what does it mean by 'use' it?

    Comment

    • JosAH
      Recognized Expert MVP
      • Mar 2007
      • 11453

      #17
      Please note that you're using an InputStream in your latest post, not a Reader
      as you used in your previous posts. Read the API documentation for those classes.

      kind regards,

      Jos

      Comment

      • jonjon0688
        New Member
        • Mar 2008
        • 14

        #18
        Originally posted by JosAH
        Please note that you're using an InputStream in your latest post, not a Reader
        as you used in your previous posts. Read the API documentation for those classes.

        kind regards,

        Jos
        no i am still using the reader in the fileSize method, the above method countChars is the one it says to use to create the fileSize method, i was just wondering how i use it?

        Comment

        • jonjon0688
          New Member
          • Mar 2008
          • 14

          #19
          Originally posted by JosAH
          What is the output and what should it be?

          kind regards,

          Jos
          it says:
          The output should have been:
          countChars

          This is what was actually produced:
          public int fileSize(String name) throws IOException
          {

          try {
          InputStreamRead er isr = new InputStreamRead er(new FileInputStream (name));
          BufferedReader in = new BufferedReader( isr);
          int charLength = 0;

          while (in.read() != -1)

          charLength++;

          return charLength;
          }

          catch (Exception e)
          {
          return -1;
          }

          Comment

          • JosAH
            Recognized Expert MVP
            • Mar 2007
            • 11453

            #20
            I'm sorry I don't understand your last post. I'd expected an (incorrect) number and
            a correct one, not an entire piece of Java source code as output from a piece of
            Java code. Please repost and please be clear about the piece of Java code you
            actually executed.

            kind regards,

            Jos

            Comment

            Working...