Google Groups no longer supports new usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Problem in Calculating the length...

0 views
Skip to the first unread message

mohamad

unread,
2 May 2006, 15:59:0402/05/2006
to
Hi I need to calculate the Length of a message saved in a text file so
i wrote the following code:
int len;
try{
FileInputStream Message_File=new FileInputStream
("C:/JBuilder4/lib/output8.txt");
BufferedReader buff=new BufferedReader(new
InputStreamReader(Message_File));
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
System.out.println(Input_Message);
len=Input_Message.length();
System.out.println(len);}
{catch......

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 :
len=Input_Message.length();
System.out.println(len);
it will give null exeption:
java.lang.NullPointerException
at final_append.CopyBytes.main(CopyBytes.java:19)
Exception in thread "main"
So what i can do????

Heiner Kücker

unread,
2 May 2006, 20:53:2102/05/2006
to
mohamad wrote

> Hi I need to calculate the Length of a message saved in a text file so
> i wrote the following code:
> int len;

int len = 0;

> try{
> FileInputStream Message_File=new FileInputStream
> ("C:/JBuilder4/lib/output8.txt");
> BufferedReader buff=new BufferedReader(new
> InputStreamReader(Message_File));
> 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
> System.out.println(Input_Message);
> len=Input_Message.length();

//summarize length values
len += Input_Message.length();
> System.out.println(len);}

} // end while

> System.out.println("entire length: " + len);}
> {catch......

--
Heiner Kücker
www.heinerkuecker.de
www.control-and-command.de

0 new messages