| | |
appending two java text files
![]() |
•
•
Join Date: May 2006
Posts: 12
Reputation:
Solved Threads: 0
hi to all...
Plz i wnt a valuable code to append two text files in java i tried alot using WriteBuffered and FileOutputStream(file,true) but without any use i wrote the following code:
it gives no errors but it doesnt append the two files plzz any good code to do so??
Plz i wnt a valuable code to append two text files in java i tried alot using WriteBuffered and FileOutputStream(file,true) but without any use i wrote the following code:
Java Syntax (Toggle Plain Text)
import java.io.*; public class append{ public static void main(String[] args) throws IOException { FileInputStream Message_File=new FileInputStream ("C:/JBuilder4/lib/input6.txt"); BufferedReader buff=new BufferedReader(new InputStreamReader(Message_File)); String Input_Message=new String(); System.out.println("Your input message is as following:"); int c; while ((c = buff.read()) != -1){ FileOutputStream out = new FileOutputStream("C:/JBuilder4/lib/output6.txt", true); buff.close(); out.close(); }} }
Last edited by cscgal; May 1st, 2006 at 9:47 pm.
•
•
Join Date: May 2006
Posts: 12
Reputation:
Solved Threads: 0
•
•
•
•
Originally Posted by server_crash
You aren't appending to the file anywhere. You create the OutputStream with the proper second parameter, but not writing to it.
Java Syntax (Toggle Plain Text)
import java.io.*; public class append_files { public static void main(String[] args) throws IOException { try { // create writer for file to append to BufferedWriter out = new BufferedWriter( new FileWriter("C:/JBuilder4/lib/output6.txt", true)); // create reader for file to append from BufferedReader in = new BufferedReader(new FileReader("C:/JBuilder4/lib/output4.txt")); String str; while ((str = in.readLine()) != null) { out.write(str); } in.close(); out.close(); } catch (IOException e) { } }}
Mohammad
Ahmad
but i need this output:
MohammadAhmad
so how can i change my code to do this???
Last edited by cscgal; May 1st, 2006 at 9:48 pm.
![]() |
Similar Threads
- Need reference to Random Accessing of Text files (C++)
- Write and Read text files (Java)
- Javac (Java)
- Making arrays from text files (VB.NET)
- lost my notebook for making text files--how do I get it back? (Windows NT / 2000 / XP)
Other Threads in the Java Forum
- Previous Thread: help plz
- Next Thread: Help please
| Thread Tools | Search this Thread |
911 actionlistener addressbook android api append applet application array arrays automation binary blackberry block bluetooth character chat class client code component consumer csv database desktop developmenthelp eclipse error fractal ftp game givemetehcodez graphics gui html ide image integer j2me j2seprojects japplet java javaarraylist javac javaee javaprojects jni jpanel julia lego linked linux list loops mac map method methods mobile netbeans newbie number objects online oriented panel printf problem program programming project projects properties recursion replaydirector reporting researchinmotion rotatetext rsa scanner se server set singleton sms sort sql string swing test textfields threads time title tree tutorial-sample ubuntu update windows working






