私はアンドロイドニュービーですので、これは些細なことと長い投稿と思われます。私は、などをGoogleで検索しているが、私は見つけることができる唯一のアンドロイドの言及は、私は私のクラスではなくさえするjava.io.InputStreamをインポートした後、これを使用してみましたテキストファイルの読み込み方法
InputStream is = getAssets().open("read_asset.txt");
int size = is.available();
// Read the entire asset into a local byte buffer.
byte[] buffer = new byte[size];
is.read(buffer);
is.close();
を参照するように見えます。それはgetAssets()でエラーを起こしました。
私はリストビューのrowIdを使用しようとしています。 テキストファイルを開き、行ごとにファイルを読み込み、 最初の16文字などの文字列配列 を生成し、配列を使用して次のアクティビティのリストビューにデータを挿入します。
String[] sectID = null; //to be loaded in listview
switch (rowId){
case 0://custom, go to section input screen
case 1:
readSectionFile s = new readSectionFile("Sect_US.dat");
sectID=s.arrayShapesAll();
私のreadSectionFileクラス(抽出)は次のとおりです。
public readSectionFile(String FileName) {
//Count the number of section records in the data file
String line = null; // String that holds current file line
int recordcount = 0; // Line number of count
try{
BufferedReader buf = new BufferedReader(new FileReader(FileName));
// Read file to count records
while ((line = buf.readLine()) != null){ //null = EOF
line = buf.readLine();
if (line.substring(0, 1).equals("*") || line.length() == 0) { //== comment or blank line
//do nothing
}else{
recordcount++;
}
}//while
buf.close();
}catch (IOException x){
x.printStackTrace();
}//end try
// Now read file to load array
mSectionIDArray = new String[recordcount + 1];
mSectionIdx = new int[recordcount + 1][2];
mData = new double[recordcount + 1][15];
int c=0;
String sectdata = null; // String that holds current file line
try {
BufferedReader buf = new BufferedReader(new FileReader(FileName));
while ((sectdata = buf.readLine()) != null){ //null = EOF
sectdata = buf.readLine();
コードはreadSectionFile S =新しいreadSectionFile( "Sect_US.dat")で動作し、クラッシュしません。
readSectionFileコードでも、bufの2番目のインスタンスはtry、catchブロックを要求するEclipseエラーを生成しますが、最初のインスタンスは受け入れられます。
私の質問は、 このテキストファイル(/ assets)を正しく開くつもりですか? 2番目のbufの使用で何が問題になっていますか?