This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes How to i save add the contents of the file to  StringBuffer? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to i save add the contents of the file to  StringBuffer?" Watch "How to i save add the contents of the file to  StringBuffer?" New topic
Author

How to i save add the contents of the file to StringBuffer?

Tran Tuan Hung
Ranch Hand

Joined: Apr 08, 2007
Posts: 59
I have an html file, i have read it, so for now i would to add the contents to
StringBuffer (read each of character then add to buffer), please suggest me
Thanks a lot!
Best regard,
Srikanth Ramu
Ranch Hand

Joined: Feb 20, 2007
Posts: 76
Use toCharArray() of String class and append() methods of StringBuffer class.

For more details:

http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html

http://java.sun.com/j2se/1.5.0/docs/api/java/lang/StringBuffer.html
[ April 15, 2007: Message edited by: Srikanth Ramu ]
Tran Tuan Hung
Ranch Hand

Joined: Apr 08, 2007
Posts: 59
Thanks for suggest, i have successed for that:
I have done it following:
FileReader fr = new FileReader("Test.html");
BufferedReader br = new BufferedReader(fr);
StringBuffer sb = new StringBuffer();
String line = br.readLine();
try {
while (line!= null) {
sb.append(line).append("\\n");
line = br.readLine();

But now, i would like to deleted tags script and contents on an file html
The detail of the problem as following:
Please help me at here, Thanks you very much
 
 
subject: How to i save add the contents of the file to StringBuffer?
 
Similar Threads
Reading File contents to a String
How i read,remove html script tags,content ?
File Contents to StringBuffer
Stringbuffer class?
I/O Question