내 데이터베이스에 저장된 경로가 text1.txt
이며 표시 할 텍스트가 포함되어 있습니다. 파일은 assets 폴더 인 assets/text1.txt에 있습니다.데이터베이스에 저장된 경로를 사용하여 assets 폴더에서 파일을 여는 방법은 무엇입니까?
이 파일을 열고 내용을 표시하려면 어떻게해야합니까?
if (placetext != null) {
try
{
InputStream textpath = getAssets().open(text);
//Bitmap bit = BitmapFactory.decodeStream(textpath);
placetext.setText(text);
//placetext.setText(text);
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
... 그리고 에뮬레이터에보기는 파일의 내용 만 text1.txt되지 않습니다 :
코드입니다.
는 이미 해결책을 가지고
문자열 text12 = b.getString ("텍스트") 시도가 { 의 InputStream은 =에 getAssets() 개방 (text12)입니다.; // int size = is.available(); 내가 여기 추측
InputStream textpath = getAssets().open(text);
: 텍스트 열 파일의 이름을 나타내므로 정상
byte[] buffer = new byte[size]; is.read(buffer); is.close(); String text= new String(buffer); placetext = (TextView)findViewById(R.id.detailText2); placetext.setText(text); } catch (IOException e) { throw new RuntimeException(e); }
감사 당신의 응답을; InputStream textpath = getAssets(). open (text), text sqlite의 path를 포함하는 필드를 나타냅니다. 그것은 이미지 파일과 이미지 경로와 함께 작동하지만, text.txt에서 작동하지 않습니다 –
당신을 환영합니다! :) 그게 효과가 있니? –
아니요, 작동하지 않습니다. ( –