2013-06-06 2 views

답변

0

다음과 같이하십시오. 그러면 원하는 파일을 읽을 수 있습니다.

File dir = Environment.getExternalStorageDirectory(); 
File yourFile = new File(dir, "path/to/the/file/inside/the/sdcard.ext"); 

시도해보십시오.

+0

감사합니다. 시도해 보겠습니다. – LeandroC

0

다음 코드를 사용할 수 있습니다.

File dir = Environment.getExternalStorageDirectory(); 
File yourFile = new File(dir, "path/to/the/file/inside/the/sdcard.ext"); 
String encodeFileToBase64Binary = encodeFileToBase64Binary(yourFile); 

private static String encodeFileToBase64Binary(File fileName) throws IOException { 
    byte[] bytes = loadFile(fileName); 
    byte[] encoded = Base64.encodeBase64(bytes); 
    String encodedString = new String(encoded); 
    return encodedString; 
} 

private static byte[] loadFile(File file) throws IOException { 
    InputStream is = new FileInputStream(file); 

    long length = file.length(); 
    if (length > Integer.MAX_VALUE) { 
     // File is too large 
    } 
    byte[] bytes = new byte[(int) length]; 
    int offset = 0; 
    int numRead = 0; 
    while (offset < bytes.length && (numRead = is.read(bytes, offset, bytes.length - offset)) >= 0) { 
     offset += numRead; 
    } 

    if (offset < bytes.length) { 
     throw new IOException("Could not completely read file " + file.getName()); 
    } 

    is.close(); 
    return bytes; 
} 
+1

감사합니다. 시도해 볼게 – LeandroC