Bookmark Topic Watch Topic
  • New Topic

Problem in using Substring  RSS feed

 
Ranet Saed
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hi ,I have a text file and it contains a message ,I want to extract the last four characters in this file and then convert it to integer i did the following:
FileInputStream Received_Message=new FileInputStream ("MyFile.txt");
BufferedReader buff2=new BufferedReader(new InputStreamReader(Received_Message));

System.out.println("Your Received message is as following:");
while((recv_Message=buff2.readLine() )!=null){
System.out.println(recv_Message);
length2 += recv_Message.length();
}

four_characters=recv_Message.substring(recv_Message.length() - 4,length2);
Four_characters_Integers = Integer.parseInt(four_characters);
i sure have try and catch and defined all varibles above
but the problem it gives me this message when i use this statement:
four_characters=recv_Message.substring(recv_Message.length() - 4,length2);
the Exception is as following:
java.lang.NumberFormatException: null
at java.lang.Integer.parseInt(Integer.java:373)
at java.lang.Integer.parseInt(Integer.java:454)
at final_append.CopyBytes.main(CopyBytes.java:101)
Exception in thread "main"
how can i solve this??plz any help in
by idea the message is as following which i need to extract the last four characters from:
5113350515586806264156901277970003516182249744328267808527911381008517422384937086806339111024080220
so the last four characters are numbers
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Report post to moderator
Repost. Please don't do that.
 
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!