Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: reading .txt files

  1. #1
    Member
    Join Date
    Jan 2012
    Posts
    57
    My Mood
    Fine
    Thanks
    11
    Thanked 0 Times in 0 Posts

    Default reading .txt files

    hello experts

    i am totally stuck here ... actually i want to read the all files that have extension .txt in my hard drive .....it may be any directory or in any path .. the problem is that i cannot specify the path it be any and my all text files can be any folder and in subfolders ...plz give some hints to rectify this problem . so that i will be able to read all the .text files of any computer ...


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,438
    My Mood
    Hungover
    Thanks
    144
    Thanked 634 Times in 542 Posts

    Default Re: reading .txt files

    What have you tried? Where are you stuck? Is this for homework? Recursion is your friend here.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Member
    Join Date
    Jan 2012
    Posts
    57
    My Mood
    Fine
    Thanks
    11
    Thanked 0 Times in 0 Posts

    Default Re: reading .txt files

    no thats not a homework ... its suddenly comes to my mind that if i want to do this kind of thing .. then how i can .. the problem which i am facing that in fileinputstream we normally specify the path and file name .
    for the name of file .. i can identify it by its .txt extension .... but how i can specify the path .. becz it can be any .. and not same for the different computers .. the idea is that suppose if user want to make a single text file of all his text files which may be any where in his system ..

  4. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,438
    My Mood
    Hungover
    Thanks
    144
    Thanked 634 Times in 542 Posts

    Default Re: reading .txt files

    Like I said, recursion is your friend here. Hint: a File instance can represent a directory. In which case, it has handy methods for listing all of the Files inside that directory (which themselves can be directories.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #5
    Member
    Join Date
    Jan 2012
    Posts
    57
    My Mood
    Fine
    Thanks
    11
    Thanked 0 Times in 0 Posts

    Default Re: reading .txt files

    ya thats right .. that means i can simply specify the drive letter and the can list all the files using list and can chk which one is directory and file having extension .txt

  6. #6
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,438
    My Mood
    Hungover
    Thanks
    144
    Thanked 634 Times in 542 Posts

    Default Re: reading .txt files

    Quote Originally Posted by deependeroracle View Post
    ya thats right .. that means i can simply specify the drive letter and the can list all the files using list and can chk which one is directory and file having extension .txt

    That's the idea, and then you'd just repeat that idea for each directory you find- which is why recursion is your friend.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  7. The Following User Says Thank You to KevinWorkman For This Useful Post:

    deependeroracle (February 9th, 2012)

Similar Threads

  1. Reading lines in files with tabs
    By imsuperman05 in forum Java Theory & Questions
    Replies: 1
    Last Post: January 14th, 2012, 11:05 AM
  2. Reading In Then Writing Out Massive Files
    By aussiemcgr in forum Java Theory & Questions
    Replies: 3
    Last Post: July 28th, 2011, 07:00 PM
  3. Reading CSV files into a program
    By Wrathgarr in forum Java Theory & Questions
    Replies: 2
    Last Post: April 15th, 2010, 10:41 AM
  4. Reading and Writing Text Files
    By kappasig84 in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: March 1st, 2010, 06:16 PM
  5. Reading many files using a scanner
    By jayjames90 in forum File I/O & Other I/O Streams
    Replies: 2
    Last Post: October 22nd, 2009, 04:35 PM