Reading a Specific Line from a file
in
Programming Questions
•
3 months ago
I am making a program that searches for music files, stores their locations in a .txt file, then goes and gets the MetaData from those files and stores that in a separate .txt file. The reason for storing in .txt files is that I ran out of memory. However, I need to be able to go and read a specific line of each of those files. The code does a great job at finding and storing those file locations, but then I need to read those file locations one at a time and go get the metadata. But How do you read lines in a file one at a time? Here is the code: **** Problem starts at the last while statement ***** and I inserted a line that just says "END" at the end of the file that stores the file locations.
- void updateFiles() {
- music = null;
- music = new File(dataPath("SongList.txt"));
- if(music.exists() == true) {
- music.delete();
- }
- music = null;
- music = new File(dataPath("SongMeta.txt"));
- if(music.exists() == true) {
- music.delete();
- }
- songList = createWriter(dataPath("SongList.txt"));
- songMeta = createWriter(dataPath("SongMeta.txt"));
- musicLocations = loadStrings(dataPath("Music Locations.txt"));
- fileNames.clear();
- search.clear();
- search.append(musicLocations);
- filesListed.clear();
- music = null;
- music = new File(dataPath("/musicFiles"));
- foundSongs = music.list(jpgFilterwav);
- addedSongs = 0;
- while(addedSongs < foundSongs.length) {
- fileNames.append(music.getAbsolutePath() + "/" + foundSongs[addedSongs]);
- addedSongs++;
- }
- foundSongs = music.list(jpgFiltermp3);
- addedSongs = 0;
- ...
- solutePath() + "/" + foundSongs[addedSongs]);
- addedSongs++;
- }
- foundSongs = music.list(jpgFiltersnd);
- addedSongs = 0;
- while(addedSongs < foundSongs.length) {
- fileNames.append(music.getAbsolutePath() + "/" + foundSongs[addedSongs]);
- addedSongs++;
- }
- if(musicLocations.length != 0) {
- musicLoaded = 0;
- while(musicLoaded < search.size()) {
- music = null;
- ...
- addedSongs = 0;
- while(addedSongs < foundSongs.length) {
- fileNames.append(music.getAbsolutePath() + "/" + foundSongs[addedSongs]);
- addedSongs++;
- }
- foundSongs = music.list(jpgFilterau);
- addedSongs = 0;
- while(addedSongs < foundSongs.length) {
- fileNames.append(music.getAbsolutePath() + "/" + foundSongs[addedSongs]);
- addedSongs++;
- }
- foundSongs = music.list(jpgFiltersnd);
- ...
- search.append(music.getAbsolutePath() + "/" + filesListed.get(searchNumber));
- }
- searchNumber++;
- }
- musicLoaded++;
- }
- skip = 0;
- }
- searchNumber = 0;
- while(searchNumber < fileNames.size()) {
- if(fileNames.get(searchNumber).indexOf("[Ljava.lang.String;") > -1) {
- fileNames.remove(searchNumber);
- searchNumber--;
- }
- searchNumber++;
- }
- }
- searchNumber = 0;
- println("Number of Songs Available: " + fileNames.size());
- while(searchNumber < fileNames.size()) {
- songList.println(fileNames.get(searchNumber));
- fileNames.remove(searchNumber);
- }
- songList.println("END");
- fileNames.clear();
- songList.flush();
- songList.close();
- searchNumber = 0;
- songListReader = createReader(dataPath("SongList.txt"));
- while(true) {
- if(songListReader.readLine().equals("END")) {
- break;
- } else {
- player = null;
- player = minim.loadFile(songListReader.readLine(), 340);
- meta = null;
- meta = player.getMetaData();
- println(meta.title() + "," + meta.album() + "," + meta.author() + "," + meta.length());
- songMeta.println(meta.title() + "," + meta.album() + "," + meta.author() + "," + meta.length());
- searchNumber++;
- }
- }
- println("Got Meta Data!");
- println(metaData.array());
- }
1