2014-06-17 5 views

답변

1

당신이 사용할 수있는 파일 이름으로 활용하려면 다음

BufferedReader br = null; 
try { 
    String sCurrentLine; 
    br = new BufferedReader(new FileReader(fileName+".csv")); 
    while ((sCurrentLine = br.readLine()) != null) { 
    System.out.println(sCurrentLine); 
    } 
} catch (IOException e) { 
    e.printStackTrace(); 
} finally { 
    try { 
    if (br != null)br.close(); 
    } catch (IOException ex) { 
    ex.printStackTrace(); 
    } 
} 
:

try { 
    String content = "Separe here integers by semi-colon"; 
    File file = new File(fileName +".csv"); 
    // if file doesnt exists, then create it 
    if (!file.exists()) { 
     file.createNewFile(); 
    } 

    FileWriter fw = new FileWriter(file.getAbsoluteFile()); 
    BufferedWriter bw = new BufferedWriter(fw); 
    bw.write(content); 
    bw.close(); 

} catch (IOException e) { 
    e.printStackTrace(); 
} 

파일을 읽으려면 :

EditText fileNameEdit= (EditText) getActivity().findViewById(R.id.fileName); 
String fileName = fileNameEdit.getText().toString(); 

그런 다음 디스크에있는 파일을 쓰기

그럼 당신은 분할 기능을 사용할 수있는 정수를합니다 :

String[] intArray = sCurrentLine.split(";"); 
+0

전체 파일 이름을 어떻게 언급합니까? 나는 EditText에서 "/ storage/sdcard0/test"를 언급하려했지만 항상 catch 블록으로 간다. AndroidManifest.xml에 WRITE_EXTERNAL_STORAGE 권한을 추가해야합니까? 도와주세요. 감사. –

+0

편집 : 완료! AndroidManifest.xml 파일에 WRITE_EXTERNAL_STORAGE 권한을 추가해야했습니다. –

0

CSV는 일반 텍스트 파일입니다. 여기서 값은 문자 ";"로 나뉩니다. 그래서, 예를 들어 BufferedWriter를 써서 작성할 수 있습니다.

BufferedWriter

관련 문제