-
-
Save bytecodeman/a410d4d48cf088d4e196e60f6825bb26 to your computer and use it in GitHub Desktop.
Read Data from a file or website
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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