Skip to content

Instantly share code, notes, and snippets.

@bytecodeman bytecodeman/ReadData.java Secret
Last active Nov 15, 2019

Embed
What would you like to do?
Read Data from a file or website
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class ReadData {
public static void main(String args[]) throws FileNotFoundException {
File file = new File("data-750-10-6.txt");
Scanner sc = new Scanner(file);
int count = sc.nextInt();
for (int i = 0; i < count; i++) {
double number = sc.nextDouble();
System.out.printf("%10.3f\n", number);
}
sc.close();
}
}
import java.io.IOException;
import java.net.URL;
import java.util.Scanner;
public class ReadDataFromURL {
public static void main(String args[]) throws IOException {
URL url = new URL("https://cs.stcc.edu/~silvestri/csc111/data-750-10-6.txt");
Scanner sc = new Scanner(url.openStream());
int count = sc.nextInt();
for (int i = 0; i < count; i++) {
double number = sc.nextDouble();
System.out.printf("%10.3f\n", number);
}
sc.close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.