2011-06-15 13 views

Respuesta

9

Debe utilizar FileConnection de JSR 75. Aquí es un breve ejemplo del uso de conexión de archivo para el archivo de lectura:

public void showFile(String fileName) { 
    try { 
     FileConnection fc = (FileConnection) 
     Connector.open("file:///CFCard/" + fileName); 
     if(!fc.exists()) { 
     throw new IOException("File does not exist"); 
     } 
     InputStream is = fc.openInputStream(); 
     byte b[] = new byte[1024]; 
     int length = is.read(b, 0, 1024); 
     System.out.println 
     ("Content of "+fileName + ": "+ new String(b, 0, length)); 
    } catch (Exception e) { 
    } 
} 

favor, eche un vistazo here para obtener más información.

1

Si sólo está preocupado con los archivos en el archivo JAR, a continuación, tienen una mira el método getResourceAsStream, el dispositivo no necesita tener JSR 75 para usarlo.