Results 1 to 3 of 3
Thread: Read and Write.. it was working
- 03-28-2011, 03:43 AM #1
Member
- Join Date
- Mar 2011
- Posts
- 27
- Rep Power
- 0
Read and Write.. it was working
Hi everyone,
I have this code since last year and now I would like to reuse it again. but right now I run it and there was no error but also there is no result.
Could anyone help me please ,,
Java Code:import java.io.*; public class ReadAndWrite{ public static void main(String args[]) throws IOException { if(args.length !=2) return; BufferedReader inStream = new BufferedReader (new FileReader("C:\\Temp\\ReadAndWrite\\File1.txt"));// to open the read stream FileWriter outStream = (new FileWriter("C:\\Temp\\ReadAndWrite\\File2.txt"));// to open the write stream String line = inStream.readLine();// put the the sentance in Line int r1 = 1; while (line != null){ outStream.write(r1+ "" + line +"\n" );// to write line = inStream.readLine(); // to read the next line r1++; }// end while inStream.close(); // close the input file outStream.close (); // close the output file }//end main }// end class
- 03-28-2011, 04:12 AM #2
Senior Member
- Join Date
- Feb 2011
- Location
- Georgia, USA
- Posts
- 122
- Rep Power
- 0
C:\\Temp\\ReadAndWrite\\File1.txt - does this file still exist?
- 03-28-2011, 04:15 AM #3
Senior Member
- Join Date
- Mar 2011
- Posts
- 261
- Rep Power
- 3
I fixed your code for you. Also make sure that these files exist.
Java Code:import java.io.*; public class ReadAndWrite{ public static void main(String args[]) throws IOException { if(args.length !=2) return; BufferedReader inStream = new BufferedReader(new File("C:\\Temp\\ReadAndWrite\\File1.txt"));// to open the read stream BufferedWriter outStream = new BufferedWriter(new PrintWriter(new File("C:\\Temp\\ReadAndWrite\\File2.txt")));// to open the write stream String line; int r1 = 1; while ((line=inStream.readLine()) != null){ outStream.write(r1+ "" + line +"\n" );// to write r1++; }// end while inStream.close(); // close the input file outStream.close (); // close the output file }//end main }// end classLast edited by Solarsonic; 03-28-2011 at 04:19 AM.
Similar Threads
-
How to get sockt to write after read??
By zardos in forum NetworkingReplies: 3Last Post: 03-04-2011, 12:00 PM -
setComment not working for me/how to write to a text file in a jar
By minime12358 in forum Advanced JavaReplies: 8Last Post: 08-06-2010, 08:41 AM -
XML read/write in Java
By bogdy.laurentiu in forum XMLReplies: 5Last Post: 05-31-2010, 06:08 PM -
How to read/write txt in Java
By megalomitis in forum New To JavaReplies: 2Last Post: 11-13-2009, 10:09 AM -
Read and Write file
By mrdestroy in forum New To JavaReplies: 13Last Post: 10-31-2008, 12:11 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks