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
  • Junilu Lacar
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Jj Roberts
  • Tim Holloway
  • Piet Souris
  • Himai Minh
  • Carey Brown
  • salvin francis

Problem in using Substring

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){
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(
at java.lang.Integer.parseInt(
at final_append.CopyBytes.main(
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:
so the last four characters are numbers
author and iconoclast
Posts: 24203
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
  • Report post to moderator
Repost. Please don't do that.
There is no beard big enough to make me comfortable enough with my masculinity to wear pink. Tiny ad:
the value of filler advertising in 2020
    Bookmark Topic Watch Topic
  • New Topic