List of usage examples for java.lang StringBuffer StringBuffer
@HotSpotIntrinsicCandidate
public StringBuffer()
From source file:Main.java
public static void main(String[] argv) throws Exception { File f = new File("C:\\test.txt"); FileReader fr = new FileReader(f); BufferedReader br = new BufferedReader(fr); StringBuffer sb = new StringBuffer(); String eachLine = br.readLine(); while (eachLine != null) { sb.append(eachLine);// w w w . j av a 2 s .c o m sb.append("\n"); eachLine = br.readLine(); } System.out.println(sb.toString()); }
From source file:MainClass.java
public static void main(String[] args) throws Exception { String hostname = "tock.usno.navy.mil"; Socket theSocket = new Socket(hostname, 13); InputStream timeStream = theSocket.getInputStream(); StringBuffer time = new StringBuffer(); int c;/*from w w w. j ava 2s. co m*/ while ((c = timeStream.read()) != -1) time.append((char) c); String timeString = time.toString().trim(); System.out.println("It is " + timeString + " at " + hostname); }
From source file:Main.java
public static void main(String[] args) throws Exception { File f = new File("hello.txt"); FileReader fr = new FileReader(f); char[] c = new char[(int) f.length()]; char[] cnew = new char[(int) f.length()]; StringBuffer sbuf = new StringBuffer(); fr.read(c, 0, (int) f.length()); int len = (int) f.length(); for (int i = 0, j = len - 1; i < len; i++, j--) { cnew[i] = c[j];/*from ww w . j a v a 2s . c o m*/ sbuf.append(cnew[i]); } System.out.println(sbuf.toString()); fr.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { File f = new File("Main.java"); FileReader fr = new FileReader(f); char[] c = new char[(int) f.length()]; char[] cnew = new char[(int) f.length()]; StringBuffer sbuf = new StringBuffer(); fr.read(c, 0, (int) f.length()); int len = (int) f.length(); for (int i = 0, j = len - 1; i < len; i++, j--) { cnew[i] = c[j];//from ww w. j av a2s . c om sbuf.append(cnew[i]); } System.out.println(sbuf.toString()); fr.close(); }
From source file:MainClass.java
public static void main(String[] av) { String joke = "dog " + "dogs"; String regEx = "dog"; Pattern doggone = Pattern.compile(regEx); Matcher m = doggone.matcher(joke); StringBuffer newJoke = new StringBuffer(); while (m.find()) { m.appendReplacement(newJoke, "goat"); }/*w w w . ja va 2 s.co m*/ m.appendTail(newJoke); System.out.println(newJoke.toString()); }
From source file:Main.java
public static void main(String args[]) { int days = 1; int month = 1; int year = 2001; SimpleDateFormat sdf = new SimpleDateFormat("E dd-MM-yyyy G"); StringBuffer buf = new StringBuffer(); Calendar cal = new GregorianCalendar(); cal.set(year, month - 1, days);/* ww w . j av a2 s.c o m*/ sdf.format(cal.getTime(), buf, new FieldPosition(10)); System.out.println(buf.toString()); }
From source file:Main.java
public static void main(String[] argv) throws Exception { CharSequence inputStr = "ab12 cd efg34 123"; String patternStr = "([a-zA-Z]+[0-9]+)"; Pattern pattern = Pattern.compile(patternStr); Matcher matcher = pattern.matcher(inputStr); StringBuffer buf = new StringBuffer(); boolean found = false; while ((found = matcher.find())) { String replaceStr = matcher.group(); matcher.appendReplacement(buf, "found<" + replaceStr + ">"); }/*from w ww . j a v a 2 s. c o m*/ matcher.appendTail(buf); String result = buf.toString(); System.out.println(result); }
From source file:HelloPeopleJDOM.java
public static void main(String[] args) throws Exception { SAXBuilder builder = new SAXBuilder(); Document doc = builder.build("./src/data.xml"); StringBuffer output = new StringBuffer(); // create the basic HTML output output.append("<html>\n").append("<head>\n<title>\nPerson List</title>\n</head>\n").append("<body>\n") .append("<ul>\n"); Iterator itr = doc.getRootElement().getChildren().iterator(); while (itr.hasNext()) { Element elem = (Element) itr.next(); output.append("<li>"); output.append(elem.getAttribute("lastName").getValue()); output.append(", "); output.append(elem.getAttribute("firstName").getValue()); output.append("</li>\n"); }/*from w ww .j a v a 2s .c om*/ // create the end of the HTML output output.append("</ul>\n</body>\n</html>"); System.out.println(output.toString()); }
From source file:Main.java
public static void main(String[] args) throws Exception { URL google = new URL("http://www.google.com/"); URLConnection googleConnection = google.openConnection(); DataInputStream dis = new DataInputStream(googleConnection.getInputStream()); StringBuffer inputLine = new StringBuffer(); String tmp;//from w w w. jav a2 s . c o m while ((tmp = dis.readLine()) != null) { inputLine.append(tmp); System.out.println(tmp); } // use inputLine.toString(); here it would have whole source dis.close(); }
From source file:MainClass.java
public static void main(String args[]) { String joke = "dog day daughter daut did do done date"; String regEx = "d"; Pattern doggone = Pattern.compile(regEx); Matcher m = doggone.matcher(joke); StringBuffer newJoke = new StringBuffer(); while (m.find()) m.appendReplacement(newJoke, "g"); m.appendTail(newJoke);/*from w w w .jav a 2s .c o m*/ System.out.println(newJoke.toString()); }