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 7 of 7

Thread: How to make Eclipse work with txt file?

  1. #1
    Junior Member
    Join Date
    Nov 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How to make Eclipse work with txt file?

    Hi everybody,

    I have Eclipse 3.6.0 installed on Window XP. Also there a sample file in C:\ called sample.txt
    The file is empty.

    Please give a code that opens this particular file and write a short word "Hello".

    Thanks!


  2. #2
    Senile Half-Wit Freaky Chris's Avatar
    Join Date
    Mar 2009
    Posts
    834
    My Mood
    Cynical
    Thanks
    7
    Thanked 105 Times in 90 Posts

    Default Re: How to make Eclipse work with txt file?

    Googling for Java File Input/Output is a good way to go. May i suggest checking out the forum rules. Announcements - What's Wrong With My Code?

    Lesson: Basic I/O (The Java™ Tutorials > Essential Classes)

    Chris

  3. #3
    Junior Member
    Join Date
    Nov 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How to make Eclipse work with txt file?

    Quote Originally Posted by Freaky Chris View Post
    Googling for Java File Input/Output is a good way to go. May i suggest checking out the forum rules. Announcements - What's Wrong With My Code?

    Lesson: Basic I/O (The Java™ Tutorials > Essential Classes)

    Chris
    Thanks for reply, Chris, but unfortunately I wasn't able to find an answer to my question from your links. Could you tell me how to write a method that would open my file and type the word there, save and close the file?

  4. #4
    Senile Half-Wit Freaky Chris's Avatar
    Join Date
    Mar 2009
    Posts
    834
    My Mood
    Cynical
    Thanks
    7
    Thanked 105 Times in 90 Posts

    Default Re: How to make Eclipse work with txt file?

    An exmaple of opening a file is given on this page Buffered Streams (The Java™ Tutorials > Essential Classes > Basic I/O)

    If you wish to program you need to learn to use APIs they are your friend. On that page a few different classes are mentioned, if you take the time to read the API for them, and the documentation example pages for thos classes, you will learn alot and be opening files in no time at all

    Chris

  5. #5
    Junior Member
    Join Date
    Nov 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How to make Eclipse work with txt file?

    Quote Originally Posted by Freaky Chris View Post
    An exmaple of opening a file is given on this page Buffered Streams (The Java™ Tutorials > Essential Classes > Basic I/O)

    If you wish to program you need to learn to use APIs they are your friend. On that page a few different classes are mentioned, if you take the time to read the API for them, and the documentation example pages for thos classes, you will learn alot and be opening files in no time at all

    Chris
    Chris, but this code doesn't work for me:

    public class FileOpener {
    inputStream = new BufferedReader(new FileReader("sample.txt"));
    }
    What am I doing wrong?
    Last edited by Prostak; November 4th, 2011 at 05:17 PM.

  6. #6
    Senile Half-Wit Freaky Chris's Avatar
    Join Date
    Mar 2009
    Posts
    834
    My Mood
    Cynical
    Thanks
    7
    Thanked 105 Times in 90 Posts

    Default Re: How to make Eclipse work with txt file?

    Can I suggest following some basic tutorials on Java,

    You seem to be missing all of the core concepts of programming in Java. I don't wish to be rude, but you do require to study some more before we can provide a sensible level of hope.

    Regards,
    Chris

  7. #7
    Junior Member
    Join Date
    Nov 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How to make Eclipse work with txt file?

    Quote Originally Posted by Freaky Chris View Post
    Can I suggest following some basic tutorials on Java,

    You seem to be missing all of the core concepts of programming in Java. I don't wish to be rude, but you do require to study some more before we can provide a sensible level of hope.

    Regards,
    Chris
    Chris, how would you open a txt file using Java? Please help.

Similar Threads

  1. Having a hard time figuring out how to make my code work
    By iainnitro in forum Loops & Control Statements
    Replies: 2
    Last Post: September 6th, 2011, 07:48 AM
  2. Code is working in Eclipse but when exported to Runnable Jar doesn't work
    By jjain.jitendra@gmail.com in forum What's Wrong With My Code?
    Replies: 1
    Last Post: August 24th, 2011, 07:12 AM
  3. what's going on? I tried to make a scrollable JFrame and it didn't work!
    By javapenguin in forum What's Wrong With My Code?
    Replies: 4
    Last Post: August 20th, 2011, 09:47 PM
  4. Replies: 1
    Last Post: March 24th, 2011, 08:22 PM
  5. How to make for loop work?
    By Dragonkndr712 in forum What's Wrong With My Code?
    Replies: 9
    Last Post: March 8th, 2011, 02:14 PM