Results 1 to 4 of 4
  1. #1
    notwist is offline Member
    Join Date
    Apr 2008
    Posts
    9
    Rep Power
    0

    Default writing text to file

    I have a quick question about writing text to a file. Why can't I just append the variable long to the file? Is there some restriction on what I can or cannot append to a file? If i just do w.write(estimateTime); the code will not compile. :confused:

    Java Code:
    //append execution time to file
    				BufferedWriter w = new BufferedWriter(new FileWriter("DESdata2.txt", true));
    				w.write(estimateTime+"\n");  //estimateTime is a variable of type long
    				w.close();

  2. #2
    sukatoa's Avatar
    sukatoa is offline Senior Member
    Join Date
    Jan 2008
    Location
    Cebu City, Philippines
    Posts
    556
    Rep Power
    7

    Default

    Have you read this?

    look for write() method and see what should be the right parameter to use.....
    freedom exists in the world of ideas

  3. #3
    notwist is offline Member
    Join Date
    Apr 2008
    Posts
    9
    Rep Power
    0

    Default

    will read!

    salamat

  4. #4
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    9

    Default

    Java Code:
    import java.io.*;
    
    public class Test {
        public static void main(String[] args) throws IOException {
            //estimateTime is a variable of type long
            long estimateTime = 250L;
            //append execution time to file
            BufferedWriter w = new BufferedWriter(new FileWriter("abc.txt", true));
            w.write((int)'a');
            w.newLine();
            String s = String.valueOf(estimateTime);
            w.write(s, 0, s.length());
            w.newLine();
            s = Long.toString(estimateTime);
            w.write(s, 0, s.length());
            w.close();
        }
    }

Similar Threads

  1. Writing text into an image and save it
    By elcapi in forum Java 2D
    Replies: 6
    Last Post: 09-18-2009, 05:47 PM
  2. Writing to a file (at the end)
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 02-08-2008, 09:22 AM
  3. Writing UTF to file using writeUTF
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-22-2008, 08:19 PM
  4. writing to a file
    By bugger in forum New To Java
    Replies: 1
    Last Post: 11-11-2007, 02:49 AM
  5. Help with File reading and writing
    By baltimore in forum New To Java
    Replies: 1
    Last Post: 07-31-2007, 06:47 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
  •