Wednesday, September 2, 2009

Read File in Source Folder (Class) Blackberry Mobile-Can use to keep constant values, Settings and certificates

Sometimes we need to keep some files within our project and use them to keep data.
for this purpose we can use this method.Once we make cod or alx we don't have to
worry about this file or its location.specially store information like top scores in some
game,settings,security certificates we can use this

public String ReadFile()
{
//This retturns the String in FileName.txt
//File must locate in Src Folder
try {
Class classs = Class.forName("packageName.ClassName");
//Source Package neme and Class name
InputStream is = classs.getResourceAsStream("/FileName.txt");
byte[] data = new byte[is.available()];
is.read(data, 0, is.available());
String c =new String(data);
return c;
}
catch (Exception ioe)
{
Dialog.alert("Error");
return null;
}
}

No comments:

Post a Comment