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

Empowering the Future of API Management: Unveiling the Journey of WSO2 API Platform for Kubernetes (APK) Project and the Anticipated Alpha Release

  Introduction In the ever-evolving realm of API management, our journey embarked on the APK project eight months ago, and now, with great a...