Example usage for java.io BufferedReader readLine

List of usage examples for java.io BufferedReader readLine

Introduction

In this page you can find the example usage for java.io BufferedReader readLine.

Prototype

public String readLine() throws IOException 

Source Link

Document

Reads a line of text.

Usage

From source file:AuthDemo.java

public static void main(String args[]) throws MalformedURLException, IOException {
    String urlString = "";
    String username = "";
    String password = "";
    Authenticator.setDefault(new MyAuthenticator(username, password));
    URL url = new URL(urlString);
    InputStream content = (InputStream) url.getContent();
    BufferedReader in = new BufferedReader(new InputStreamReader(content));
    String line;//from   w  ww  .  j av  a2s  .com
    while ((line = in.readLine()) != null) {
        System.out.println(line);
    }
    System.out.println("Done.");
}

From source file:MainClass.java

public static void main(String args[]) throws Exception {
    ProcessBuilder launcher = new ProcessBuilder();
    Map<String, String> environment = launcher.environment();
    launcher.redirectErrorStream(true);/*w w  w .j ava 2 s .  c  om*/
    launcher.directory(new File("c:\\"));

    environment.put("name", "var");
    launcher.command("notepad.exe");
    Process p = launcher.start(); // And launch a new process
    BufferedReader output = new BufferedReader(new InputStreamReader(p.getInputStream()));
    String line;
    while ((line = output.readLine()) != null)
        System.out.println(line);

    // The process should be done now, but wait to be sure.
    p.waitFor();

}

From source file:Main.java

public static void main(String[] args) throws Exception {
    DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder domBuilder = domFactory.newDocumentBuilder();

    Document newDoc = domBuilder.newDocument();
    Element rootElement = newDoc.createElement("CSV2XML");
    newDoc.appendChild(rootElement);/*from   w  w w.  jav a  2  s . c o  m*/

    BufferedReader csvReader = new BufferedReader(new FileReader("csvFileName.txt"));
    String curLine = csvReader.readLine();
    String[] csvFields = curLine.split(",");
    Element rowElement = newDoc.createElement("row");
    for (String value : csvFields) {
        Element curElement = newDoc.createElement(value);
        curElement.appendChild(newDoc.createTextNode(value));
        rowElement.appendChild(curElement);
        rootElement.appendChild(rowElement);
    }
    csvReader.close();
    TransformerFactory tranFactory = TransformerFactory.newInstance();
    Transformer aTransformer = tranFactory.newTransformer();
    Source src = new DOMSource(newDoc);
    Result dest = new StreamResult(new File("xmlFileName"));
    aTransformer.transform(src, dest);
}

From source file:Main.java

public static void main(String args[]) throws IOException {
    String data, answer = "";
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    System.out.println("Enter any String : ");
    data = br.readLine();
    char[] findupper = data.toCharArray();
    for (int i = 0; i < findupper.length; i++) {
        if (findupper[i] >= 65 && findupper[i] <= 91) // ascii value in between 65
                                                      // and 91 is A to Z
        {// www .  j a  v  a 2  s.co  m
            answer += findupper[i]; // adding only uppercase
        }
    }
    System.out.println("Answer : " + answer);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    String data = URLEncoder.encode("key1", "UTF-8") + "=" + URLEncoder.encode("value1", "UTF-8");
    data += "&" + URLEncoder.encode("key2", "UTF-8") + "=" + URLEncoder.encode("value2", "UTF-8");

    URL url = new URL("http://server.com:80/cgi");
    URLConnection conn = url.openConnection();
    conn.setDoOutput(true);/*from  w  w  w  . j a v  a2  s  . c  o m*/
    OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
    wr.write(data);
    wr.flush();

    BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
    String line;
    while ((line = rd.readLine()) != null) {
        System.out.println(line);
    }
    wr.close();
    rd.close();
}

From source file:SourceReader.java

public static void main(String[] arguments) {
    try {//from  w w  w .ja  va 2  s .  co m
        FileReader file = new FileReader("SourceReader.java");
        BufferedReader buff = new BufferedReader(file);
        boolean eof = false;
        while (!eof) {
            String line = buff.readLine();
            if (line == null)
                eof = true;
            else
                System.out.println(line);
        }
        buff.close();
    } catch (IOException e) {
        System.out.println("Error - " + e.toString());
    }
}

From source file:Main.java

public static void main(String[] arguments) throws Exception {
    StringBuffer output = new StringBuffer();

    FileReader file = new FileReader("a.htm");
    BufferedReader buff = new BufferedReader(file);
    boolean eof = false;
    while (!eof) {
        String line = buff.readLine();
        if (line == null)
            eof = true;//from   ww w . j a  va  2 s  .com
        else
            output.append(line + "\n");
    }
    buff.close();

    String page = output.toString();
    Pattern pattern = Pattern.compile("<a.+href=\"(.+?)\"");
    Matcher matcher = pattern.matcher(page);
    while (matcher.find()) {
        System.out.println(matcher.group(1));
    }
}

From source file:Main.java

public static void main(String args[]) throws Exception {
    String fullURL = args[0];/*from   w  w  w  . ja  v a  2s . c  om*/
    URL u = new URL(fullURL);
    URLConnection conn = u.openConnection();
    conn.setDoInput(true);
    OutputStream theControl = conn.getOutputStream();
    BufferedWriter out = new BufferedWriter(new OutputStreamWriter(theControl));
    for (int i = 1; i < args.length; i++) {
        out.write(args[i] + "\n");
    }
    out.close();
    InputStream theData = conn.getInputStream();

    String contentType = conn.getContentType();
    if (contentType.toLowerCase().startsWith("text")) {
        BufferedReader in = new BufferedReader(new InputStreamReader(theData));
        String line;
        while ((line = in.readLine()) != null) {
            System.out.println(line);
        }
    }
}

From source file:Main.java

public static void main(String args[]) throws Exception {
    String fullURL = args[0];// ww  w  . j a  va2s  .  c  o m
    URL u = new URL(fullURL);
    URLConnection conn = u.openConnection();
    conn.setDoOutput(true);
    OutputStream theControl = conn.getOutputStream();
    BufferedWriter out = new BufferedWriter(new OutputStreamWriter(theControl));
    for (int i = 1; i < args.length; i++) {
        out.write(args[i] + "\n");
    }
    out.close();
    InputStream theData = conn.getInputStream();

    String contentType = conn.getContentType();
    if (contentType.toLowerCase().startsWith("text")) {
        BufferedReader in = new BufferedReader(new InputStreamReader(theData));
        String line;
        while ((line = in.readLine()) != null) {
            System.out.println(line);
        }
    }
}

From source file:Main.java

public static void main(String[] arg) throws Exception {
    BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
    while (true) {
        String sLine = bf.readLine();
        System.out.println("::" + sLine);
    }//from www . ja va 2s  .  co  m
}