Androidのアセットフォルダーからファイルを読み込もうとしていますが、これは私がこれまでに持っているものです
public class TestingMusicDAO {
private static final String TAG_NAME = "MUSIC_TESTING_DAO";
private static List<Song> songs;
private ContentResolver contentResolver;
private static Context testingcontext;
private File fFile;
InputStream inputStream = null;
public TestingMusicDAO( Context context) throws IOException{
Log.d(TAG_NAME, "Setting up testing songs");
contentResolver = context.getContentResolver();
testingcontext = context;
getAllSongsFromFile();
}
public static void getAllSongsFromFile() throws IOException{
Log.d( TAG_NAME, "Tryign to Get all Songs" );
InputStream is;
is = testingcontext.getAssets().open("testing");
Log.d( TAG_NAME, "Did that work?" );
BufferedReader bufferReader = new BufferedReader(new InputStreamReader(is));
String inputLine;
while((inputLine = bufferReader.readLine()) != null){
processLine(inputLine);
}
bufferReader.close();
}
private static void logSongs() {
for(Song song : songs)
Log.d( TAG_NAME, song.toString() );
}
public List<Song> getAllSongs() {
return songs;
}
public static void processLine(String aLine) {
Scanner scanner = new Scanner(aLine);
scanner.useDelimiter("=");
if(scanner.hasNext()){
String title = scanner.next();
String artist = scanner.next();
String album = scanner.next();
String id = scanner.next();
String albumId = scanner.next();
String trackOrder = scanner.next();
Log.d(TAG_NAME, "Title = " + title + "Artist = " + artist + "Album = " + album + "ID = " + id + "AlbumID = " + albumId);
}
else {
Log.d(TAG_NAME, "Empty or invalid line. Unable to process");
}
}
}
したがって、基本的に TestingMusicDAO コンストラクターを呼び出し、そこからファイルの各行を個別に読み取って解析できるようにしたいのですが、FileNotFoundExecption: testing が引き続き発生します。どんなアイデアも素晴らしいでしょうありがとう!
ピーター、