This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Problem in Calculating the Length... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Problem in Calculating the Length..." Watch "Problem in Calculating the Length..." New topic

Problem in Calculating the Length...

Ranet Saed

Joined: May 02, 2006
Posts: 7
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(
Exception in thread "main"
So what i can do???

Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
Instead of simply assigning the new length to the variable len, you need to accumulate those lengths.
Justin Fox
Ranch Hand

Joined: Jan 24, 2006
Posts: 802
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


You down with OOP? Yeah you know me!
jQuery in Action, 2nd edition
subject: Problem in Calculating the Length...
Similar Threads
New Problem
Problem with searching for a file which is in the zip file
Continue for my problem(plz help me in)
Problem in Files (plz help me in???)