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

Thread: Writing in a file using Java

  1. #1
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 286 Times in 225 Posts
    Blog Entries
    4

    Post Writing in a file using Java

    import java.io.*;
     
    public class WriteFile {
     
        public static void main(String[] args) throws IOException {
     
        Writer output = null;
        File file = new File("myFile.txt");
        output = new BufferedWriter(new FileWriter(file));
        output.write("Whatever string you want here");
        output.close();
        System.out.println("File written");   
     
        }
    }
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

    Looking for a Java job? Visit - Java Programming Careers


  2. #2
    Junior Member
    Join Date
    Dec 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by JavaPF View Post
    import java.io.*;
     
    public class WriteFile {
     
        public static void main(String[] args) throws IOException {
     
        Writer output = null;
        File file = new File("myFile.txt");
        output = new BufferedWriter(new FileWriter(file));
        output.write("Whatever string you want here");
        output.close();
        System.out.println("File written");   
     
        }
    }
    Wouls this create a new file if it is not found?

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    18,560
    Thanks
    45
    Thanked 1,954 Times in 1,928 Posts

    Default Re: How to write a file using Java

    Would this create a new file if it is not found?
    Have you tested it? What happened?

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

    Default

    Quote Originally Posted by Norm View Post
    Have you tested it? What happened?
    Not yet sorry.

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    18,560
    Thanks
    45
    Thanked 1,954 Times in 1,928 Posts

    Default Re: How to write a file using Java

    You should start your own thread if you have any more questions or problems.

Similar Threads

  1. How to Write a simple XMPP (Jabber) client using the Smack API
    By JavaPF in forum Java Networking Tutorials
    Replies: 34
    Last Post: May 15th, 2013, 02:25 AM
  2. How to rename a file in your computer in Java?
    By JavaPF in forum File Input/Output Tutorials
    Replies: 1
    Last Post: December 24th, 2011, 11:05 AM