Results 1 to 7 of 7
- 09-26-2008, 04:48 PM #1
Member
- Join Date
- Sep 2008
- Posts
- 3
- Rep Power
- 0
[SOLVED] Need help with file reader
Hi
I need help with something. I need to write a program in java that reads the CD rom drive gives me count of all the files with specific extension. So i am looking somehting like this.
label: (shows the label of the CD)
txt: number of .txt files on the CD
.jiff: number of .jiff files on the CD
thats it. Any help would be greatly appreciated.
thanks
Syed
- 09-26-2008, 05:47 PM #2
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
Well, what do you and what compiler/error messages are you getting from it. We are not simply going to do your (home)work for you (although hardwired might).
- 09-26-2008, 06:01 PM #3
Member
- Join Date
- Sep 2008
- Posts
- 3
- Rep Power
- 0
hi
thanks for your reply. i do not expect u to do the homework. this is what i got so far.
import java.io.File;
import java.util.Arrays;
public class DirectoryTestMain
{
public static void main(String[] args)
{
// create a file that is really a directory
File aDirectory = new File("C://");
// get a listing of all files in the directory
String[] filesInDir = aDirectory.list();
// sort the list of files (optional)
Arrays.sort(filesInDir);
// have everything i need, just print it now
for ( int i=0; i<filesInDir.length; i++ )
{
System.out.println( "file: " + filesInDir[i] );
}
}
}
can you help with this and modify it so that it does what i am wanting it to do?
thanks
- 09-26-2008, 06:22 PM #4
1) How will you get the address of the CD? Are you going to hardcode it like you have for the C: drive?
2)When you get your list of files, you need to look at the end of the filename for the extensions you want to count. Look at the String class for methods to do that.For example: endswith or indexOf
3) don't know how to get the label.
- 09-26-2008, 07:20 PM #5
Member
- Join Date
- Sep 2008
- Posts
- 3
- Rep Power
- 0
Hi
Yes i will hardcode the CD
2. When you get your list of files, you need to look at the end of the filename for the extensions you want to count. Look at the String class for methods to do that.For example: endswith or indexOf
Not sure i know how to do it? can you help or give a little example? any help is appreciated.
thanks
- 09-26-2008, 08:12 PM #6
have you read the String class's API doc? Did you see the methods I mentioned? If you don't have a copy of the API doc, I suggest you get one as you'll need it.
The code might be something like this:
if(aString.endsWith("Ext")) {
// process Strings ending with Ext
- 09-27-2008, 07:43 PM #7
Similar Threads
-
FileReader / Buffered Reader
By sepaht in forum New To JavaReplies: 9Last Post: 07-10-2008, 08:05 PM -
[SOLVED] reader and writer on same file handle
By Nicholas Jordan in forum Advanced JavaReplies: 11Last Post: 07-01-2008, 03:39 AM -
A simple DOM reader
By Java Tip in forum Java TipReplies: 0Last Post: 01-03-2008, 09:24 AM -
help with file reader
By jason27131 in forum New To JavaReplies: 1Last Post: 08-01-2007, 03:03 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks