ただ、アンドロイド の資産フォルダにテキストファイルを置くには https://stackoverflow.com/a/5771369/5409229
サンプルコード
XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
</LinearLayout>
Androidのコード
package com.javasamples;
//reading an embedded RAW data file
import android.app.Activity;
import android.os.Bundle;
import android.widget.Toast;
import java.io.*;
public class FileDemo1 extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
try {
PlayWithRawFiles();
} catch (IOException e) {
Toast.makeText(getApplicationContext(),
"Problems: " + e.getMessage(), 1).show();
}
}// onCreate
public void PlayWithRawFiles() throws IOException {
String str="";
StringBuffer buf = new StringBuffer();
InputStream is = this.getResources().openRawResource(R.myfolder.text_file);
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
if (is!=null) {
while ((str = reader.readLine()) != null) {
buf.append(str + "\n");
}
}
is.close();
Toast.makeText(getBaseContext(),
buf.toString(), Toast.LENGTH_LONG).show();
}// PlayWithSDFiles
} // FilesDemo4
例えばこの回答を参照してください@チャンドランパティルチェックiこれがうまくいけば答えが返ってくる –
これはうまくいきましたが、drawableフォルダには.txtファイルが保存されていないので、 "R.drawable.my_base_data"という行を "R.myfolder.text_file"に変更しなければなりませんでした。 resフォルダに新しいディレクトリを作成しました。 ありがとうございました。 –
@ chandraman-patilそして、回答を受け入れます。 –