StringBuffer « Development « Java I/O Q&A





1. Parsing of StringBuffer(URGENT)    coderanch.com

Hi, I have defined String Buffer of 2K capacity. Server is send me data withing that capacity of string Buffer. After StringBuffer recieves data from the server on client side, I want to parse it. I have delimeter ":" to parse the stringBuffer? I tried to use StringTokenizer, Substring. But I can't get it. Here is my example: import java.applet.Applet; import ...

2. File Contents to StringBuffer    coderanch.com

3. StringBuffer containing '\n'    coderanch.com

I have the following stringbuffer StringBuffer sb = new StringBuffer("This is first line"); sb.append("\n"); sb.append("This is second line"); sb.append("\n"); And I need to write this stringbuffer to a file hoping that some IO classes would help to recognize the '\n' character. The file should look like this: This is first line This is second line I would like to know if ...

4. Save contents of stringbuffer to new/existing file in ROOT directory    coderanch.com

Thanks for the reply. I have a servlet that obtains a connection to my database and reads various records from a products table. I then loop through the resultset, re-format and add the fields of my choice to a string buffer, similar to CSV format. I have got this far and have the data ready to send to the file. I ...

5. Problem in finding " \' " in String or StringBuffer.    coderanch.com

Hi , in my program my need is to find \' in a string which i am reading from file. now problem is java considering "\" as an escape char. i cant change contents of file manually from "\'" to "\\'" Help : can someone help me in finding that. or is there anyway to off the escape char or to ...

6. StringBuffer to File - Need Example    coderanch.com

import java.io.*; public class Test { public static void main(String[] args) { try { StringBuffer data = new StringBuffer("test data in StringBuffer"); // write it to file writeToFile("test.txt",data); // read it back from file data = readFromFile("test.txt"); System.out.println("data = " + data.toString()); } catch (Exception e) { e.printStackTrace(); } } public static void writeToFile(String pFilename, StringBuffer pData) throws IOException { BufferedWriter ...

8. Need help in parsing the Stringbuffer    coderanch.com

1) create a String[] that can hold all your Strings. You can calculate its size easily: Math.ceil(transactions.length() / 120.0) (in normal words: the length divided by 120, rounded up). 2) Loop through the StringBuffer in increments of 120: for (int start = 0; start < transactions.length(); start += 120) 3) In the loop use StringBuffer.substring(start, end). I'm sure you'll be able ...

9. Read a Flat File line by line and add it to a StringBuffer    coderanch.com

You never change item. You read one line, then keep using the same line over and over. You'll see that usually one of the following (nearly identical) loops is used: // 1 String item = in.readLine(); while (item != null) { ... item = in.readLine(); } // 2; this is 1 but the assignment is included in the guard String item; ...





10. Do I need to use a stringbuffer?    coderanch.com

11. StringBuffer wrong result when write to a file    forums.oracle.com

You seem to believe that converting a String with two chars into bytes will result in two bytes. That isn't necessarily the case, especially for non-ASCII characters. And it's possible that your system's default encoding will not convert non-ASCII characters into bytes which are bit-by-bit identical. So I don't know what the point of that exercise was, but I'm not surprised ...

12. stringBuffer.append(char) now throws IOException?!? HUH?!?    forums.oracle.com

I recently had the 1.5 JDK shoved down my throat, and today was the first time I actually had to compile anything in it. And I suddenly found 7 compiler errors complaining that I'm appending to a StringBuffer without dealing with IOExceptions. Two questions: 1. Yes, I eventually figured out that StringBuffer inherits this requirement from the new "Appendable" interface, but ...

13. Writing a StringBuffer to file (without using toString)    forums.oracle.com

Hi there, I have some data in a StringBuffer which needs written out to a file. Previously I've simply used the toString() method of StringBuffer, i.e. myWriter.write(myBuffer.toString()); However I encounter problems when the StringBuffer gets really big (around 10 million characters) - an out of memory error is generated when calling the toString() method. Is there a way to write this ...