• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
  • salvin francis
  • Frits Walraven
  • Piet Souris

Problem in Calculating the Length...

Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi I need to calculate the Length of a message saved in a text file so
i wrote the following code:
int len;
FileInputStream Message_File=new FileInputStream
BufferedReader buff=new BufferedReader(new
String Input_Message=new String();
System.out.println("Your input message is as following:");
while((Input_Message=buff.readLine() )!=null){
// Calculating the the length of our message in unit of bits

this will only give me the length of the last line in the Mesage not
the length of all the message ,so when I Put this statement after while
loop :
it will give null exeption:
at final_append.CopyBytes.main(CopyBytes.java:19)
Exception in thread "main"
So what i can do???

Ranch Hand
Posts: 2410
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Instead of simply assigning the new length to the variable len, you need to accumulate those lengths.
Ranch Hand
Posts: 802
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i dont know what kinda of value the variable would be, but you could

set up a variable, which i saw you say byte.

so do this in the while loop..

info += len;

so every time it adds the length of input_w/e to info.

hope this helps a lil

    Bookmark Topic Watch Topic
  • New Topic