2012-05-14 5 views
0

onDeviceReady 내에서 window.requestFileSystem ...을 호출하는 대신 PhoneGap의 설명서에서 제공하는 예제를 따르려고합니다. 실제로 특정 파일에 액세스해야 할 때마다 호출하고 있습니다. 웬일인지, 나의 코드는 그 선로를지나 가지 않는 것처럼 보인다.PhoneGap에서 SD 카드의 파일을 읽는 방법?

function pullSelectRecord(link) 
{ 
    selectedFile = link; 
    window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail); 
} 

function gotFS(fileSystem) { 
     alert("this is" + selectedFile); 
     fileSystem.root.getFile(link, null, gotFileEntry, fail); 
    } 

    function gotFileEntry(fileEntry) { 
     fileEntry.file(gotFile, fail); 
    } 

    function gotFile(file){ 
     readDataUrl(file); 
     readAsText(file); 
    } 

function readAsText(file) { 
     var reader = new FileReader(); 
     reader.onloadend = function(evt) { 
      alert(evt.target.result); 
     }; 
     reader.readAsText(file); 
    } 

답변

1

어디서든 requestFileSystem을 호출 할 수 있습니다. 그 라인을 넘지 않는다면, "adb logcat"을보고 오류가 무엇인지를 알아야 할 것입니다. 또한 Manifest.xml에 외부 저장소 쓰기 권한이 있는지 확인하십시오.

관련 문제