Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem in reading a file

 
naresh govindaswmay
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
I have attached the file here.while calling this method it will return null value please check it and let me know the scope of the variable..


package com.security.file;
import java.io.FileInputStream;
import java.io.ObjectInputStream;
import java.util.ArrayList;

public class FileObjectInputStream {

public String getObjetFromFile()
{
String userHome=null;
ObjectInputStream streamInObj=null;
userHome=System.getProperty("user.home");
userHome=userHome.concat("\\Application Data\\SecurityPin\\Security.property");
//System.out.println("userhome-->"+userHome);
Object listr=null;
try
{
System.out.println("try");
streamInObj=new ObjectInputStream(new FileInputStream(userHome));
System.out.println("after");
listr=streamInObj.readObject();
//System.out.println(listr.getClass());
System.out.println("file==>"+listr);


}catch(Exception E)
{
E.getMessage();
}
finally
{
try
{
streamInObj.close();
}catch(Exception e)
{
e.getMessage();
}
}
return (String)listr;

}
public static void main(String[] args) {
FileObjectInputStream obj=new FileObjectInputStream();
System.out.println(obj.getObjetFromFile());
}

}

ourput is -->try
null. please check it and let me know.it is very urgent.
 
Ulf Dittmer
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In I/O code it's not a good idea to ignore exceptions. In both catch blocks you should at least print a warning, or -even better- the stack trace of the exception, or you'll never know that were was a problem.

Also, when posting code of any length, please UseCodeTags.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic