List of usage examples for java.lang StringBuffer toString
@Override @HotSpotIntrinsicCandidate public synchronized String 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);/*from w w w . j a va 2 s . com*/ 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 { 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);/*from w ww . jav a2s. com*/ sb.append("\n"); eachLine = br.readLine(); } System.out.println(sb.toString()); }
From source file:FileDialogMultipleFileNameSelection.java
public static void main(String[] args) { Display display = new Display(); final Shell shell = new Shell(display); FileDialog dlg = new FileDialog(shell, SWT.MULTI); Collection files = new ArrayList(); if (dlg.open() != null) { String[] names = dlg.getFileNames(); for (int i = 0, n = names.length; i < n; i++) { StringBuffer buf = new StringBuffer(dlg.getFilterPath()); if (buf.charAt(buf.length() - 1) != File.separatorChar) buf.append(File.separatorChar); buf.append(names[i]);/*from w ww. j a v a 2 s. co m*/ files.add(buf.toString()); } } System.out.println(files); display.dispose(); }
From source file:com.rest.samples.getTipoCambioBanxico.java
public static void main(String[] args) { String url = "http://www.banxico.org.mx/tipcamb/llenarTiposCambioAction.do?idioma=sp"; try {/*w w w . j a va 2 s. c o m*/ HttpClient hc = HttpClientBuilder.create().build(); HttpGet request = new HttpGet(url); request.setHeader("User-Agent", "Mozilla/5.0"); request.setHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); HttpResponse res = hc.execute(request); if (res.getStatusLine().getStatusCode() != 200) { throw new RuntimeException("Failed : HTTP eror code: " + res.getStatusLine().getStatusCode()); } BufferedReader rd = new BufferedReader(new InputStreamReader(res.getEntity().getContent())); StringBuffer result = new StringBuffer(); String line = ""; while ((line = rd.readLine()) != null) { result.append(line); } Document doc = Jsoup.parse(result.toString()); Element tipoCambioFix = doc.getElementById("FIX_DATO"); System.out.println(tipoCambioFix.text()); } catch (IOException ex) { Logger.getLogger(SamplesUseHttpclient.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:MainClass.java
public static void main(String[] args) throws IOException { SSLServerSocketFactory ssf = (SSLServerSocketFactory) SSLServerSocketFactory.getDefault(); ServerSocket ss = ssf.createServerSocket(8080); while (true) { try {/*from w ww . j a v a 2 s . c o m*/ Socket s = ss.accept(); OutputStream out = s.getOutputStream(); BufferedReader in = new BufferedReader(new InputStreamReader(s.getInputStream())); String line = null; while (((line = in.readLine()) != null) && (!("".equals(line)))) { System.out.println(line); } StringBuffer buffer = new StringBuffer(); buffer.append("<HTML><HEAD><TITLE>HTTPS Server</TITLE></HEAD>\n"); buffer.append("<BODY>\n<H1>Success!</H1></BODY></HTML>\n"); String string = buffer.toString(); byte[] data = string.getBytes(); out.write("HTTP/1.0 200 OK\n".getBytes()); out.write(new String("Content-Length: " + data.length + "\n").getBytes()); out.write("Content-Type: text/html\n\n".getBytes()); out.write(data); out.flush(); out.close(); in.close(); s.close(); } catch (Exception e) { e.printStackTrace(); } } }
From source file:ZipDemo.java
public static void main(String[] args) throws Exception { for (int i = 0; i < args.length; ++i) { String uncompressed = ""; File f = new File(args[i]); if (f.exists()) { BufferedReader br = new BufferedReader(new FileReader(f)); String line = ""; StringBuffer buffer = new StringBuffer(); while ((line = br.readLine()) != null) buffer.append(line);/*from www . ja va 2 s.com*/ br.close(); uncompressed = buffer.toString(); } else { uncompressed = args[i]; } byte[] compressed = ZipDemo.compress(uncompressed); String compressedAsString = new String(compressed); byte[] bytesFromCompressedAsString = compressedAsString.getBytes(); bytesFromCompressedAsString.equals(compressed); System.out.println(ZipDemo.uncompress(compressed)); System.out.println(ZipDemo.uncompress(compressedAsString)); } }
From source file:MainClass.java
public static void main(String args[]) { Pattern p = Pattern.compile("(\\w+) (\\w+)"); StringBuffer sb = new StringBuffer(); String candidateString = "Jack Lee"; String replacement = "$2, $1"; Matcher matcher = p.matcher(candidateString); matcher.matches();//from w w w . j a v a2 s . c o m matcher.appendReplacement(sb, replacement); System.out.println(sb.toString()); }
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 va 2 s .co 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 w ww . jav a 2 s. c o m sbuf.append(cnew[i]); } System.out.println(sbuf.toString()); fr.close(); }
From source file:StringBufferDemo.java
public static void main(String[] argv) { String s1 = "Hello" + ", " + "World"; System.out.println(s1);/*from w w w .ja va 2 s. c o m*/ // Build a StringBuffer, and append some things to it. StringBuffer sb2 = new StringBuffer(); sb2.append("Hello"); sb2.append(','); sb2.append(' '); sb2.append("World"); // Get the StringBuffer's value as a String, and print it. String s2 = sb2.toString(); System.out.println(s2); // Now do the above all over again, but in a more // concise (and typical "real-world" Java) fashion. StringBuffer sb3 = new StringBuffer().append("Hello").append(',').append(' ').append("World"); System.out.println(sb3.toString()); // Exercise for the reader: do it all AGAIN but without // creating any temporary variables. }