Results 1 to 3 of 3
  1. #1
    right2001 is offline Member
    Join Date
    Feb 2009
    Posts
    25
    Rep Power
    0

    Default Creating&Saving as a different Text file

    :confused::confused::confused:

    I have read the data from one text file from database.
    After reading the data I have modified or edit the data with some special char.
    Now I would like to save into a different text file.
    How I do it well?

    :confused::confused::confused:

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

  3. #3
    right2001 is offline Member
    Join Date
    Feb 2009
    Posts
    25
    Rep Power
    0

    Default

    Here is my program. I try to append some whitespace after each word, and copy in a different file. However, it only writes last word and the whitespace in the new file. Anybody has a comment?

    import java.io.BufferedReader;
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.FileReader;
    import java.io.IOException;
    import java.util.Scanner;


    class ReadFile {

    public static void main(String[] args) {
    /*
    System.out.println("enter the source");
    InputStreamReader source = new InputStreamReader(System.in);
    */
    Scanner s = null;
    try {
    s = new Scanner(new BufferedReader(new FileReader("d:in.txt")));
    } catch (FileNotFoundException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }

    while (s.hasNext()) {
    StringBuffer sb = new StringBuffer(s.next());
    String a= sb.append("\t \r\n\t /*heey*/").toString();
    byte[] b= a.getBytes();
    writeFile(b);

    }
    }

    public static void writeFile (byte[] z){

    FileOutputStream out = null;


    try {
    out = new FileOutputStream("d:out.txt");
    } catch (FileNotFoundException e1) {
    // TODO Auto-generated catch block
    e1.printStackTrace();
    }

    try {
    out.write(z);

    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }


    }}

Similar Threads

  1. Saving To A New Line Using A Text File
    By jadaleus in forum Advanced Java
    Replies: 10
    Last Post: 10-24-2008, 07:21 PM
  2. Saving To A New Line Using A Text File
    By jadaleus in forum Advanced Java
    Replies: 1
    Last Post: 10-24-2008, 12:31 AM
  3. saving to a new line a text
    By jadaleus in forum Advanced Java
    Replies: 1
    Last Post: 10-20-2008, 06:10 PM
  4. Saving to a Text File
    By jadaleus in forum Advanced Java
    Replies: 2
    Last Post: 10-17-2008, 06:50 PM

Posting Permissions

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