Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

I need to write ID3 tags

843785Jul 12 2008 — edited Jul 13 2008
I used a program which messed up all my ID3 tags. What i have been able to find so far on the forums allows me to read the ID3 tags but i now to write the correct tags back. I am not really sure how to use external packages so i was wondering if there was a way to do it without additional libraries. I use JGrasp at the moment, my current code is below which when the file is placed in the same directory as the files it will print out all ID3 data.
   import java.io.*; 

 
    public class ReadID3 { 
       public static void main(String[] arguments) { 
         try { 
            File song = new File("."); 
            File [] list = song.listFiles();
            for(int i=0;i<list.length;i++)
            {
               FileInputStream file = new FileInputStream(list); 
int size = (int)list[i].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(" does not contain"
+ " ID3 info.");
file.close();
}
}
catch (Exception e) {
System.out.println("Error ? " + e.toString());
}

}
}

Thanks for any help.
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 10 2008
Added on Jul 12 2008
10 comments
404 views