Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 09-26-2008, 05:48 PM
Member
 
Join Date: Sep 2008
Posts: 3
Rep Power: 0
syed.shuvo is on a distinguished road
Default [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
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 09-26-2008, 06:47 PM
Senior Member
 
Join Date: Jun 2008
Posts: 1,397
Rep Power: 3
masijade is on a distinguished road
Default
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).
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 09-26-2008, 07:01 PM
Member
 
Join Date: Sep 2008
Posts: 3
Rep Power: 0
syed.shuvo is on a distinguished road
Default
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
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 09-26-2008, 07:22 PM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: SouthWest Missouri, USA
Posts: 2,229
Rep Power: 4
Norm is on a distinguished road
Default
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.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 09-26-2008, 08:20 PM
Member
 
Join Date: Sep 2008
Posts: 3
Rep Power: 0
syed.shuvo is on a distinguished road
Default
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
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 09-26-2008, 09:12 PM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: SouthWest Missouri, USA
Posts: 2,229
Rep Power: 4
Norm is on a distinguished road
Default
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
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 09-27-2008, 08:43 PM
Darryl.Burke's Avatar
Senior Member
 
Join Date: Sep 2008
Location: Madgaon, Goa, India
Posts: 742
Rep Power: 2
Darryl.Burke is on a distinguished road
Default
Quote:
i do not expect u to do the homework. this is what i got so far.
The code was lifted from devdaily[dot]com

This question is also cross posted at the Sun Java forums (threadID=5335084)

db
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
FileReader / Buffered Reader sepaht New To Java 9 07-10-2008 09:05 PM
[SOLVED] reader and writer on same file handle Nicholas Jordan Advanced Java 11 07-01-2008 04:39 AM
A simple DOM reader Java Tip Java Tips 0 01-03-2008 10:24 AM
help with file reader jason27131 New To Java 1 08-01-2007 04:03 AM


All times are GMT +2. The time now is 05:17 PM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org