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: help me to save file with io

  1. #1
    Junior Member
    Join Date
    Sep 2012
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question help me to save file with io

    i make a java program that type code on frame . who compaile or run our code on frame output is transfer to our textArea . but when i trasfer that code to a file for save it from io. it save sucessfully but new line is not in my program . every think in single line . what i do help me

    here is my code
    file=new File("C:/vijay");
    System.out.println("documentry created :- "+file.mkdir());
    try
    {
    file=File.createTempFile("JavaApplication",".java" ,file);
    fos=new FileOutputStream(file);
    dos=new DataOutputStream(fos);
     
    String demo=jta1.getText();
    String demo1[]=demo.split("\n");
    System.out.println(/*demo1[0]+*/" :- "+ch);
    /*dos.writeUTF(demo);
     
    DataInputStream dis=new DataInputStream(new FileInputStream(file));
    String s=dis.readUTF();
    System.out.println(s);
    jta1.setText(s);*/
     
    byte b[]=demo.getBytes();
    dos.write(b);
     
    }catch(Exception e)	{System.out.println(e);}

    i used so many method of DataOutputStream and FileOutputStream in io for do it.


  2. #2
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: help me to save file with io

    String demo1[]=demo.split("\n"); is removing your new line characters. Either stop removing them or put them back in.
    System.out.println(/*demo1[0]+*/" :- "+ch); Where is the variable ch defined? Please be sure to include all relevant code when posting.

  3. #3
    Junior Member
    Join Date
    Sep 2012
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: help me to save file with io

    bro its not working . if it worked then why i post it here . when i use this method all string is transfer to demo1[0] and null in the next string . any other method bro which is not in my program or toll me whats the mistake i am doing here ? and sorry for ch . it in the double cortestion like "ch" . help me pls

  4. #4
    Junior Member
    Join Date
    Sep 2012
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: help me to save file with io

    all that method in that program are not working . i checked

  5. #5
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: help me to save file with io

    Quote Originally Posted by vijay1807 View Post
    bro its not working . if it worked then why i post it here . when i use this method all string is transfer to demo1[0] and null in the next string . any other method bro which is not in my program or toll me whats the mistake i am doing here ? and sorry for ch . it in the double cortestion like "ch" . help me pls
    I didn't give you the code to use. I told you what your code is doing and gave you a link to the method you are using. That method is removing your new line character. -Either stop removing it, or figure out a way to put it back in.

Similar Threads

  1. Save results in an excel file
    By helensyk in forum What's Wrong With My Code?
    Replies: 1
    Last Post: July 31st, 2012, 09:43 AM
  2. Need help to save Canvas content to a file
    By piulitza in forum AWT / Java Swing
    Replies: 3
    Last Post: December 27th, 2011, 11:20 AM
  3. trying to save data onto a file
    By DanTheSand in forum File I/O & Other I/O Streams
    Replies: 4
    Last Post: December 13th, 2011, 09:58 AM
  4. Save form as .pdf file?
    By Taron in forum AWT / Java Swing
    Replies: 3
    Last Post: November 14th, 2010, 02:20 PM
  5. Saving .jsp page as .pdf file while generating report for struts based web application
    By ravindra_kumar_tiwari in forum JavaServer Pages: JSP & JSTL
    Replies: 3
    Last Post: August 12th, 2008, 09:32 AM