Results 1 to 5 of 5

Thread: What is filewriter in java?

  1. #1
    Join Date
    May 2009
    Posts
    1,010

    What is filewriter in java?

    Hi,
    I am computer science student. I recently started learning java language. When I reading java book there is "filewriter" concept I unable to understand. So if you have any knowledge about this please help me.

  2. #2
    Join Date
    Apr 2008
    Posts
    1,948

    Re: What is filewriter in java?

    It is a type of class. Filewriter creates a new file and give you chance to write into that file.
    Following is the summary of construction:
    FileWriter(File newfile)
    This creates FileWriter object.It is not useful as compared to PrintWriter class.

  3. #3
    Join Date
    May 2008
    Posts
    2,012

    Re: What is filewriter in java?

    FileWriter class extends the OutputStreamWriter. It is one of the user friendly class for writing character in the file. This class accept character encoding. FileWriter class also accepts byte-buffer size. For this construction you have to create OutputStreamWriter for FileOutputStream. FileWriter is usually made for writing characters using streams.

  4. #4
    Join Date
    Apr 2008
    Posts
    2,005

    Re: What is filewriter in java?

    Following is the example of filewriter:


    Code:
    // Demonstrate FileWriter.
    import java.io.*;
    class FileWriter {
    public static void main(String args[]) throws Exception {
    String s = "Day after tomorrow\\n"
    + " all world will destroy\\n"
    + " and no one live";
    char b[] = new char[s.length()];
    source.getChars(0, s.length(), b, 0);
    FileWriter F0 = new FileWriter("file1.txt");
    for (int p=0; p < b.length; p += 2) {
    F0.write(b[p]);
    }
    f0.close();
    FileWriter F1 = new FileWriter("file2.txt");
    F1.write(b);
    F1.close();
    FileWriter F2 = new FileWriter("file3.txt");
    F2.write(b,b.lengthbuffer.
    length/4,b.length/4);
    F2.close();
    }
    }

  5. #5
    Join Date
    May 2008
    Posts
    2,297

    Re: What is filewriter in java?

    Code:
    import java.io.FileWriter;
    import java.io.IOException;
    
    public class MC {
      public static void main(String[] a1) {
        FileWriter w;
        try {
          w = new FileWriter("amol.txt");
          char c = 'Q';
          w.write(c);
          w.close();
        } catch (IOException e) {
         
          e.printStackTrace();
        }
    
      }
    }

Similar Threads

  1. Replies: 4
    Last Post: 04-09-2013, 11:04 PM
  2. FileReader API and FileWriter API in HTML5
    By Gyunaya in forum Software Development
    Replies: 6
    Last Post: 25-02-2011, 11:16 AM
  3. Setting Of Java to The Point At Manual Java
    By winni in forum Software Development
    Replies: 4
    Last Post: 10-01-2011, 10:05 PM
  4. Link List Example in Java Sample program in Java
    By trickson in forum Software Development
    Replies: 2
    Last Post: 04-08-2009, 08:23 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,283,053.82893 seconds with 17 queries