I am a java novice trying to go through the book listed in the title of this post. This is also my first question to post on stack overflow. There does not appear to be a forum for the book so I decided to ask here.
I am on Chapter 20: Reading and Writing Files in Java 24 Hours and have gotten to the ID3Reader.java project. I am using Netbeans 7 to create this project. The code is supposed to analyze an MP3 file (which I have made my argument using the absolute path) and skip everything but the last 128 bytes. Then, the remaining bytes are examined to see if they contain any ID3 data. If they do, the first three bytes are the numbers 84, 65, 71. Then it displays the title, the artist, the album and the year in a descending order.
import java.io.*;
public class ID3Reader {
public static void main(String[] arguments) {
try {
File song = new File(arguments[0]);
FileInputStream file = new FileInputStream(song);
int size = (int) song.length();
file.skip(size - 128);
byte[] last128 = new byte[128];
file.read(last128);
String id3 = new String(last128);
String tag = id3.substring(0, 3);
if (tag.equals("TAG")) {
System.out.println("Title: " + id3.substring(3, 32));
System.out.println("Artist: " + id3.substring(33, 62));
System.out.println("Album: " + id3.substring(63, 91));
System.out.println("Year: " + id3.substring(93, 97));
} else {
System.out.println(arguments[0] + " does not contain"
+ " ID3 info.");
}
file.close();
} catch (Exception e) {
System.out.println("Error — " + e.toString());
}
}
Again I have set the argument to exactly where the MP3 file is and have even got the code from the website for this book.
C:\Documents and Settings\Administrator\My Documents\NetBeansProjects\Java24\Where The Moon Came From - Moonbrows (Twin Of Pangaea).
But instead I get this error.
Error — java.io.FileNotFoundException: C:\Documents (The system cannot find the file specified)
I have pulled my hair out trying to find something that would help me on this problem but I just cannot seem to find anything that I can translate to this problem. I would very much appreciate any information that you can give me. If there is any more information that is needed to be known before you can answer just say the word an I will get it.
C:\Documents and Settings\Administrator\My Documents\NetBeansProjects\Java24\Where The Moon Came From - Moonbrows (Twin Of Pangaea)
Do you have that file? Maybe you forgot the .mp3
at the end, or maybe you never had the file in the first place. If not, change the path to where your file is like this:
C:\Users\Somebody\Desktop\song.mp3
Also, if you want spaces in a path you must use quotes:
"C:\Path with spaces\More spaces\song_thing.mp3"