Results 1 to 7 of 7
  1. #1
    syed.shuvo is offline Member
    Join Date
    Sep 2008
    Posts
    3
    Rep Power
    0

    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

  2. #2
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    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).

  3. #3
    syed.shuvo is offline Member
    Join Date
    Sep 2008
    Posts
    3
    Rep Power
    0

    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

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,397
    Rep Power
    25

    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.

  5. #5
    syed.shuvo is offline Member
    Join Date
    Sep 2008
    Posts
    3
    Rep Power
    0

    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

  6. #6
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,397
    Rep Power
    25

    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

  7. #7
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,234
    Rep Power
    19

    Default

    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

Similar Threads

  1. FileReader / Buffered Reader
    By sepaht in forum New To Java
    Replies: 9
    Last Post: 07-10-2008, 08:05 PM
  2. [SOLVED] reader and writer on same file handle
    By Nicholas Jordan in forum Advanced Java
    Replies: 11
    Last Post: 07-01-2008, 03:39 AM
  3. A simple DOM reader
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-03-2008, 09:24 AM
  4. help with file reader
    By jason27131 in forum New To Java
    Replies: 1
    Last Post: 08-01-2007, 03:03 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •