aspose file tools*
The moose likes I/O and Streams and the fly likes getting a filename Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "getting a filename" Watch "getting a filename" New topic
Author

getting a filename

Pisces Iscariot
Greenhorn

Joined: Sep 21, 2005
Posts: 4
I have to make a database of an mp3 collection where all the mp3's are actually .txt files with nothing in them. I have to put them in some kind of collection which shouldnt be a problem for me. The problem is that I don't know how to get the file and folder names themselves in order to add them to the database. So folder names would be like "Rolling Stones - 40 Licks" with file names within being "01 - Same Old Crap.txt" I have no idea where to start on this, any help is appreciated, thanks!
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
I would use the java.io.File class. It has methods to let you list all files and directories within a directory and methods to determine whether it is a file or directory.
Kia Phia Ben
Ranch Hand

Joined: Dec 16, 2005
Posts: 48
I think
File file = new File(name);
name is file name or folder.

and detect file music follow by
if(file.isFile()){

if( file.getName().indexOf(".mp3") > 0);
System.out.print("this is a file mp3");
}
Sam Codean
Ranch Hand

Joined: Feb 26, 2006
Posts: 194
Yes that is correct but a small addition if you do not mind

=====================
I think
File file = new File(name);
name is file name or folder.

and detect file music follow by
if(file.isFile()){

if( file.getName().indexOf(".mp3") > 0);
System.out.print("this is a file mp3");
}

======================================
File file = new File(name);

if(file.isFile()){
String fileName = file.getName();

if( (fileName.lastIndexOf(".mp3")+1) ==
(fileName.length()-".mp3".length())
)
System.out.print("this is a file mp3");
}


Even better is to place the extension in a Constant and use that.


-Sam Codean<br />SCJP 1.4 (98%)<br />SCJD 5.0 (87.5%)
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
Um, I would suggest that last part could be

or possibly


"I'm not back." - Bill Harding, Twister
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: getting a filename
 
Similar Threads
Applet wav to mp3 conversion - tritonus plugins, lame dlls
Changing FilePath from full filepath to project folder filepath
problem with accessing mp3 file in tomcat
how to read and list files in Jsp List
jsp design question