Linki

Snippety

  1. BufferedReader, BufferedWriter
    BufferedReader br = new BufferedReader(new FileReader(sPlik))
    BufferedWriter bw = new BufferedWriter(new FileWriter(sPlik));
  2. exec
    aRuntime.getRuntime().exec("command", null, new File("katalog"));

    ProcessBuilder pb = new ProcessBuilder("latex", "/tmp/deal.tex");
    pb.directory(new File("/tmp"));
    pb.redirectErrorStream(true);
    pb.start().;

    // przekierować wyjście na System.out nie jest łatwo

    java.awt.Desktop.getDesktop().open("/tmp/deal.pdf");

  3. regular expressions
    // $1 as a replacement, .*+ not greedy
    sJarName = System.getProperty("java.class.path").replaceFirst("^.*[\\\\/](.*jar).*$", "$1");
  4. resources
    Class.forName("MagLab").getResourceAsStream
  5. URLConnection
    URLConnection uc = new URL(sUrl + "/" + sFile).openConnection();
    uc.getInputStream();
  6. XML
    Element doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new File(sOutFile)).getDocumentElement();
    NodeList lst = doc.getChildNodes();
    for (i=0; i<lst.getLength(); i++) {
    if (lst.item(i).getNodeName().equals("test:index")) {
    System.out.println(((Element)lst.item(i)).getAttribute("href"));
    }
    }