Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Java
  4. Adding text to an existing file or create it if not existant

Adding text to an existing file or create it if not existant

Scheduled Pinned Locked Moved Java
helpjavaquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Matjaz xyz
    wrote on last edited by
    #1

    Hi. I'm new at Java... also helping my girlfriend to do her work (sigh:P).... Anyway... im stuck a bit at adding text to an existing file... Is there any simple way editing this? try { PrintWriter inFile= new PrintWriter(new FileWriter("Text.txt")); PrintWriter inFile1= new PrintWriter(new FileWriter("Text1.txt")); for (SOMETHING Element:Something) { izhod.println(Element.inFile()); izhod1.println(Element.inFile1()); } inFile.close(); inFile1.close(); } catch(Exception e) { System.out.println("Error."); } Or must i rewrite everything and use buffered reader? If thats so, can you show me what to do :) Thanks in advance!

    Regards, Matjaž

    T L 2 Replies Last reply
    0
    • M Matjaz xyz

      Hi. I'm new at Java... also helping my girlfriend to do her work (sigh:P).... Anyway... im stuck a bit at adding text to an existing file... Is there any simple way editing this? try { PrintWriter inFile= new PrintWriter(new FileWriter("Text.txt")); PrintWriter inFile1= new PrintWriter(new FileWriter("Text1.txt")); for (SOMETHING Element:Something) { izhod.println(Element.inFile()); izhod1.println(Element.inFile1()); } inFile.close(); inFile1.close(); } catch(Exception e) { System.out.println("Error."); } Or must i rewrite everything and use buffered reader? If thats so, can you show me what to do :) Thanks in advance!

      Regards, Matjaž

      T Offline
      T Offline
      TorstenH
      wrote on last edited by
      #2

      japp, try to use BufferedReder and BufferedWriter - if allowed by your teacher ;) There are great Tutorials at oracle.com:Big Index @ oracle.com[^] please bookmarks that one and refer to it when having trouble. They are really well made. For your current situation I'd suggest File I/O operations[^] regards Torsten

      I never finish anyth...

      1 Reply Last reply
      0
      • M Matjaz xyz

        Hi. I'm new at Java... also helping my girlfriend to do her work (sigh:P).... Anyway... im stuck a bit at adding text to an existing file... Is there any simple way editing this? try { PrintWriter inFile= new PrintWriter(new FileWriter("Text.txt")); PrintWriter inFile1= new PrintWriter(new FileWriter("Text1.txt")); for (SOMETHING Element:Something) { izhod.println(Element.inFile()); izhod1.println(Element.inFile1()); } inFile.close(); inFile1.close(); } catch(Exception e) { System.out.println("Error."); } Or must i rewrite everything and use buffered reader? If thats so, can you show me what to do :) Thanks in advance!

        Regards, Matjaž

        L Offline
        L Offline
        lanmingle
        wrote on last edited by
        #3

        Ha ha! You are good! I come from China, I love programming, a student, my English is good bad, I came here to learn more technical and handed foreign friends, thank you! Is there any way I can chat with you, I want to speak English, MSN it? Or e-mail?

        Hi ! My name lanmingle , i from china .

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups