Results 1 to 3 of 3
- 04-07-2009, 03:41 AM #1
Member
- Join Date
- Feb 2009
- Posts
- 25
- Rep Power
- 0
Creating&Saving as a different Text file
:confused::confused::confused:
I have read the data from one text file from database.
After reading the data I have modified or edit the data with some special char.
Now I would like to save into a different text file.
How I do it well?
:confused::confused::confused:
- 04-07-2009, 04:22 AM #2
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
What you have tried so far? First show your effort here.
- 04-07-2009, 07:17 AM #3
Member
- Join Date
- Feb 2009
- Posts
- 25
- Rep Power
- 0
Here is my program. I try to append some whitespace after each word, and copy in a different file. However, it only writes last word and the whitespace in the new file. Anybody has a comment?
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.util.Scanner;
class ReadFile {
public static void main(String[] args) {
/*
System.out.println("enter the source");
InputStreamReader source = new InputStreamReader(System.in);
*/
Scanner s = null;
try {
s = new Scanner(new BufferedReader(new FileReader("d:in.txt")));
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
while (s.hasNext()) {
StringBuffer sb = new StringBuffer(s.next());
String a= sb.append("\t \r\n\t /*heey*/").toString();
byte[] b= a.getBytes();
writeFile(b);
}
}
public static void writeFile (byte[] z){
FileOutputStream out = null;
try {
out = new FileOutputStream("d:out.txt");
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
out.write(z);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}}
Similar Threads
-
Saving To A New Line Using A Text File
By jadaleus in forum Advanced JavaReplies: 10Last Post: 10-24-2008, 07:21 PM -
Saving To A New Line Using A Text File
By jadaleus in forum Advanced JavaReplies: 1Last Post: 10-24-2008, 12:31 AM -
saving to a new line a text
By jadaleus in forum Advanced JavaReplies: 1Last Post: 10-20-2008, 06:10 PM -
Saving to a Text File
By jadaleus in forum Advanced JavaReplies: 2Last Post: 10-17-2008, 06:50 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks