Adding text to an existing file or create it if not existant
-
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ž
-
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ž
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...
-
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ž
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 .