File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes I/O and Streams and the fly likes problem in  reading a file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "problem in  reading a file" Watch "problem in  reading a file" New topic
Author

problem in reading a file

naresh govindaswmay
Ranch Hand

Joined: Aug 15, 2007
Posts: 90
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.


Thanks and Regards<br />Naresh govindaswamy
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41839
    
  63
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.


Ping & DNS - my free Android networking tools app
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: problem in reading a file