Example usage for java.util Scanner hasNextLine

List of usage examples for java.util Scanner hasNextLine

Introduction

In this page you can find the example usage for java.util Scanner hasNextLine.

Prototype

public boolean hasNextLine() 

Source Link

Document

Returns true if there is another line in the input of this scanner.

Usage

From source file:Main.java

public static void main(String[] args) throws Exception {
    File file = new File("data.txt");

    Scanner scanner = new Scanner(file);
    while (scanner.hasNextLine()) {
        String line = scanner.nextLine();
        System.out.println(line);
    }//from  w w  w .j a va 2 s  .c  o  m
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    File file = new File("data.txt");
    Scanner scanner = new Scanner(file);
    while (scanner.hasNextLine()) {
        String line = scanner.nextLine();

        Scanner lineScanner = new Scanner(line);
        lineScanner.useDelimiter(",");
        while (lineScanner.hasNext()) {
            String part = lineScanner.next();
            System.out.print(part + ", ");
        }/*from  w  w w  . ja  va  2s  .co  m*/
        System.out.println();
    }
}

From source file:SocketTest.java

public static void main(String[] args) {
    try {//w  ww  .  ja v  a  2 s. com
        Socket s = new Socket("time-A.timefreq.bldrdoc.gov", 13);
        try {
            InputStream inStream = s.getInputStream();
            Scanner in = new Scanner(inStream);

            while (in.hasNextLine()) {
                String line = in.nextLine();
                System.out.println(line);
            }
        } finally {
            s.close();
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:org.apache.commons.net.examples.cidr.SubnetUtilsExample.java

public static void main(String[] args) {
    String subnet = "192.168.0.3/31";
    SubnetUtils utils = new SubnetUtils(subnet);
    SubnetInfo info = utils.getInfo();//from  w  ww  .j ava2 s .c  om

    System.out.printf("Subnet Information for %s:%n", subnet);
    System.out.println("--------------------------------------");
    System.out.printf("IP Address:\t\t\t%s\t[%s]%n", info.getAddress(),
            Integer.toBinaryString(info.asInteger(info.getAddress())));
    System.out.printf("Netmask:\t\t\t%s\t[%s]%n", info.getNetmask(),
            Integer.toBinaryString(info.asInteger(info.getNetmask())));
    System.out.printf("CIDR Representation:\t\t%s%n%n", info.getCidrSignature());

    System.out.printf("Supplied IP Address:\t\t%s%n%n", info.getAddress());

    System.out.printf("Network Address:\t\t%s\t[%s]%n", info.getNetworkAddress(),
            Integer.toBinaryString(info.asInteger(info.getNetworkAddress())));
    System.out.printf("Broadcast Address:\t\t%s\t[%s]%n", info.getBroadcastAddress(),
            Integer.toBinaryString(info.asInteger(info.getBroadcastAddress())));
    System.out.printf("Low Address:\t\t\t%s\t[%s]%n", info.getLowAddress(),
            Integer.toBinaryString(info.asInteger(info.getLowAddress())));
    System.out.printf("High Address:\t\t\t%s\t[%s]%n", info.getHighAddress(),
            Integer.toBinaryString(info.asInteger(info.getHighAddress())));

    System.out.printf("Total usable addresses: \t%d%n", Long.valueOf(info.getAddressCountLong()));
    System.out.printf("Address List: %s%n%n", Arrays.toString(info.getAllAddresses()));

    final String prompt = "Enter an IP address (e.g. 192.168.0.10):";
    System.out.println(prompt);
    Scanner scanner = new Scanner(System.in);
    while (scanner.hasNextLine()) {
        String address = scanner.nextLine();
        System.out.println("The IP address [" + address + "] is " + (info.isInRange(address) ? "" : "not ")
                + "within the subnet [" + subnet + "]");
        System.out.println(prompt);
    }
    scanner.close();
}

From source file:examples.cidr.SubnetUtilsExample.java

public static void main(String[] args) {
    String subnet = "192.168.0.3/31";
    SubnetUtils utils = new SubnetUtils(subnet);
    SubnetInfo info = utils.getInfo();/*  w  ww .j  a va  2s .c  om*/

    System.out.printf("Subnet Information for %s:\n", subnet);
    System.out.println("--------------------------------------");
    System.out.printf("IP Address:\t\t\t%s\t[%s]\n", info.getAddress(),
            Integer.toBinaryString(info.asInteger(info.getAddress())));
    System.out.printf("Netmask:\t\t\t%s\t[%s]\n", info.getNetmask(),
            Integer.toBinaryString(info.asInteger(info.getNetmask())));
    System.out.printf("CIDR Representation:\t\t%s\n\n", info.getCidrSignature());

    System.out.printf("Supplied IP Address:\t\t%s\n\n", info.getAddress());

    System.out.printf("Network Address:\t\t%s\t[%s]\n", info.getNetworkAddress(),
            Integer.toBinaryString(info.asInteger(info.getNetworkAddress())));
    System.out.printf("Broadcast Address:\t\t%s\t[%s]\n", info.getBroadcastAddress(),
            Integer.toBinaryString(info.asInteger(info.getBroadcastAddress())));
    System.out.printf("Low Address:\t\t\t%s\t[%s]\n", info.getLowAddress(),
            Integer.toBinaryString(info.asInteger(info.getLowAddress())));
    System.out.printf("High Address:\t\t\t%s\t[%s]\n", info.getHighAddress(),
            Integer.toBinaryString(info.asInteger(info.getHighAddress())));

    System.out.printf("Total usable addresses: \t%d\n", Integer.valueOf(info.getAddressCount()));
    System.out.printf("Address List: %s\n\n", Arrays.toString(info.getAllAddresses()));

    final String prompt = "Enter an IP address (e.g. 192.168.0.10):";
    System.out.println(prompt);
    Scanner scanner = new Scanner(System.in);
    while (scanner.hasNextLine()) {
        String address = scanner.nextLine();
        System.out.println("The IP address [" + address + "] is " + (info.isInRange(address) ? "" : "not ")
                + "within the subnet [" + subnet + "]");
        System.out.println(prompt);
    }

}

From source file:examples.SubnetUtilsExample.java

public static void main(String[] args) {
    String subnet = "192.168.0.1/29";
    SubnetUtils utils = new SubnetUtils(subnet);
    SubnetInfo info = utils.getInfo();//from w w  w  . ja  v a 2 s. c o m

    System.out.printf("Subnet Information for %s:\n", subnet);
    System.out.println("--------------------------------------");
    System.out.printf("IP Address:\t\t\t%s\t[%s]\n", info.getAddress(),
            Integer.toBinaryString(info.asInteger(info.getAddress())));
    System.out.printf("Netmask:\t\t\t%s\t[%s]\n", info.getNetmask(),
            Integer.toBinaryString(info.asInteger(info.getNetmask())));
    System.out.printf("CIDR Representation:\t\t%s\n\n", info.getCidrSignature());

    System.out.printf("Supplied IP Address:\t\t%s\n\n", info.getAddress());

    System.out.printf("Network Address:\t\t%s\t[%s]\n", info.getNetworkAddress(),
            Integer.toBinaryString(info.asInteger(info.getNetworkAddress())));
    System.out.printf("Broadcast Address:\t\t%s\t[%s]\n", info.getBroadcastAddress(),
            Integer.toBinaryString(info.asInteger(info.getBroadcastAddress())));
    System.out.printf("First Usable Address:\t\t%s\t[%s]\n", info.getLowAddress(),
            Integer.toBinaryString(info.asInteger(info.getLowAddress())));
    System.out.printf("Last Usable Address:\t\t%s\t[%s]\n", info.getHighAddress(),
            Integer.toBinaryString(info.asInteger(info.getHighAddress())));

    System.out.printf("Total usable addresses: \t%d\n", info.getAddressCount());
    System.out.printf("Address List: %s\n\n", Arrays.toString(info.getAllAddresses()));

    final String prompt = "Enter an IP address (e.g. 192.168.0.10):";
    System.out.println(prompt);
    Scanner scanner = new Scanner(System.in);
    while (scanner.hasNextLine()) {
        String address = scanner.nextLine();
        System.out.println("The IP address [" + address + "] is " + (info.isInRange(address) ? "" : "not ")
                + "within the subnet [" + subnet + "]");
        System.out.println(prompt);
    }

}

From source file:drpc.BptiEnsembleQuery.java

public static void main(final String[] args) throws IOException, TException, DRPCExecutionException {
    if (args.length < 3) {
        System.err.println("Where are the arguments? args -- DrpcServer DrpcFunctionName folder");
        return;//from w ww  .  ja v  a2s. co  m
    }

    final DRPCClient client = new DRPCClient(args[0], 3772, 1000000 /*timeout*/);
    final Queue<String> featureFiles = new ArrayDeque<String>();
    SpoutUtils.listFilesForFolder(new File(args[2]), featureFiles);

    Scanner scanner = new Scanner(featureFiles.peek());
    int i = 0;
    while (scanner.hasNextLine() && i++ < 1) {
        List<Map<String, List<Double>>> dict = SpoutUtils.pythonDictToJava(scanner.nextLine());
        for (Map<String, List<Double>> map : dict) {
            final Double[] features = map.get("chi1").toArray(new Double[0]);
            final Double[] moreFeatures = map.get("chi2").toArray(new Double[0]);
            final Double[] both = (Double[]) ArrayUtils.addAll(features, moreFeatures);
            final String parameters = serializeFeatureVector(ArrayUtils.toPrimitive(both));
            Logger.getAnonymousLogger().log(Level.INFO, runQuery(args[1], parameters, client));
        }
    }
    client.close();
}

From source file:flashcrawler.FlashCrawler.java

/**
 * @param args the command line arguments
 *///ww w . j  av a  2 s  .  c om
public static void main(String[] args) throws FileNotFoundException {
    Scanner scn = new Scanner(new File("input.txt"));
    ArrayList<String> ins = new ArrayList();
    while (scn.hasNextLine()) {
        String input = scn.nextLine();
        ins.add(input);
    }

    String URL;
    PrintWriter writer = null;
    writer = new PrintWriter(new FileOutputStream(new File("error-log.txt"), true));

    String File;
    for (String name : ins) {
        File offlinePath = new File("/games/" + name + ".swf");
        String onlinePath = "http://wsh.gamib.com/x/" + name + "/" + name + ".swf";
        System.out.println("Downloading " + onlinePath + " into " + offlinePath);
        URL url = null;
        try {
            System.out.println("...");
            url = new URL(onlinePath);
        } catch (MalformedURLException ex) {
            System.out.println("Failed to create url object");
            writer.println("Error when creating url: " + onlinePath + "\tname");
        }
        try {
            System.out.println("...");
            FileUtils.copyURLToFile(url, offlinePath);
            System.out.println("Success.");
        } catch (IOException ex) {
            System.out.println("Error when downloading game: " + offlinePath);
            writer.println("Error when downloading game: " + offlinePath);
        }

    }
    writer.close();
    System.out.println("Process complete!");
}

From source file:Main.java

public static void main(String[] args) {

    String s = "java2s.com \n 1 + 1 = 2.0 ";

    Scanner scanner = new Scanner(s);

    // print the next line
    System.out.println(scanner.nextLine());

    // check if there is a next line again
    System.out.println(scanner.hasNextLine());

    System.out.println(scanner.nextLine());

    // check if there is a next line again
    System.out.println(scanner.hasNextLine());

    scanner.close();/*from  w ww. j  a v a  2s . c om*/
}

From source file:drpc.KMeansDrpcQuery.java

public static void main(final String[] args)
        throws IOException, TException, DRPCExecutionException, DecoderException, ClassNotFoundException {
    if (args.length < 3) {
        System.err.println("Where are the arguments? args -- DrpcServer DrpcFunctionName folder");
        return;/* w  w  w  .  j  av  a2s .  c  om*/
    }

    final DRPCClient client = new DRPCClient(args[0], 3772, 1000000 /*timeout*/);
    final Queue<String> featureFiles = new ArrayDeque<String>();
    SpoutUtils.listFilesForFolder(new File(args[2]), featureFiles);

    Scanner scanner = new Scanner(featureFiles.peek());
    int i = 0;
    while (scanner.hasNextLine() && i++ < 10) {
        List<Map<String, List<Double>>> dict = SpoutUtils.pythonDictToJava(scanner.nextLine());
        for (Map<String, List<Double>> map : dict) {
            i++;

            Double[] features = map.get("chi2").toArray(new Double[0]);
            Double[] moreFeatures = map.get("chi1").toArray(new Double[0]);
            Double[] rmsd = map.get("rmsd").toArray(new Double[0]);
            Double[] both = (Double[]) ArrayUtils.addAll(features, moreFeatures);
            String parameters = serializeFeatureVector(ArrayUtils.toPrimitive(both));

            String centroidsSerialized = runQuery(args[1], parameters, client);

            Gson gson = new Gson();
            Object[] deserialized = gson.fromJson(centroidsSerialized, Object[].class);

            for (Object obj : deserialized) {
                // result we get is of the form List<result>
                List l = ((List) obj);
                centroidsSerialized = (String) l.get(0);

                String[] centroidSerializedArrays = centroidsSerialized
                        .split(MlStormClustererQuery.KmeansClustererQuery.CENTROID_DELIM);
                List<double[]> centroids = new ArrayList<double[]>();
                for (String centroid : centroidSerializedArrays) {
                    centroids.add(MlStormFeatureVectorUtils.deserializeToFeatureVector(centroid));
                }

                double[] rmsdPrimitive = ArrayUtils.toPrimitive(both);
                double[] rmsdKmeans = new double[centroids.size()];

                for (int k = 0; k < centroids.size(); k++) {
                    System.out.println("centroid        -- " + Arrays.toString(centroids.get(k)));
                    double[] centroid = centroids.get(k);
                    rmsdKmeans[k] = computeRootMeanSquare(centroid);
                }

                System.out.println("1 rmsd original -- " + Arrays.toString(rmsd));
                System.out.println("2 rmsd k- Means -- " + Arrays.toString(rmsdKmeans));
                System.out.println();
            }

        }
    }
    client.close();
}