Abrindo e lendo arquivos em dispositivos móveis

O Framework de conexão genérica do pacote javax.microedition.io pode ser usado para abrir arquivos em dispositivos móveis.

O código abaixo mostrtra como abrir um arquivo e ler a partir do uso de um Framework de conexão genérica:

try
{
  InputConnection fc = (FileConnection)Connector.open(
    "file://hello.txt");

  InputStream fis = fc.openInputStream();
  DataInputStream fdi = new DataInputStream(fis);

  int ch;
  String str = new String();

  while ( (ch = fdi.read()) != -1
  {
    str+=((char)ch);
  }

  fdi.close();
  fis.close();
  fc.close();
}
catch(IOException e){}