안드로이드 개발 질문/답변
(글 수 45,052)
TextView tv = new TextView(this);
try{
tv.setText(readtest());
}catch(IOException e){}
setContentView(tv);
}
private String readtest() throws IOException {
String test;
FileInputStream textfis = new FileInputStream("/sdcard/textTest.txt");
BufferedInputStream textbis = new BufferedInputStream(textfis);
test=textbis.read()+"";
return test ;
}
아직은 이렇게 간단한 소스인데요
txt파일 이 읽어오는것 까지는 성공한것 같은데
영어 문장을 하나 써놓았던 txt파일이 87이라는 값만 표시 합니다.
텍스트 파일 코딩을 다시 해야하나요??
아니면 소스 자체내에서 해결할수 있나요?
아마 ansi로 코딩된 txt파일인데...유니코드는 불러올수 있나요?
2011.07.13 12:31:13
앗 죄송합니다.
문제를 잘못 인지 했내요
BufferedReader bufferReader = null;
FileInputStream fis = null;
String strPath = null;
try {
final File path = new File(Environment.getExternalStorageDirectory()+File.separator+fileName);
fis = new FileInputStream(path);
bufferReader = new BufferedReader(new InputStreamReader(fis,"euc-kr")); //<-- 이부분을 한번 참조 해보세요
while( (strPath = bufferReader.readLine()) !=null ){
int failAdd = SQLHelper.sharedInstance().addDataBase(tableName ,strPath);
failCnt += failAdd;
if( failAdd == 0 ){
recvCnt++;
}
total++;
}
} catch (FileNotFoundException e) {
//e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally {
try{
if( fis != null )fis.close();
if( bufferReader != null )bufferReader.close();
}catch(IOException e){}
}해결이 되었으면 좋겠내요




final File path = new File(Environment.getExternalStorageDirectory()+File.separator+"textTest.txt");
FileInputStream textfis = new FileInputStream(path );
이런식으로 해보세요 파일 위치 경로를 잘못 선언해 주신것 같내요