Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.util.Scanner;
- public class erettsegi {
- public static void main (String[] args){
- //String text = readString("penztar.txt");
- //System.out.println(text);
- String[] words = readArray("penztar.txt");
- for (int i = 0; i < words.length; i++){
- System.out.println(words[i]);
- }
- }
- public static String[] readArray(String file){
- int ctr = 0;
- try {
- @SuppressWarnings("resource")
- Scanner s1 = new Scanner(new File(file));
- while (s1.hasNextLine()){
- ctr++;
- s1.next();
- }
- String[] words = new String[ctr];
- @SuppressWarnings("resource")
- Scanner s2 = new Scanner(new File(file));
- for (int i = 0; i < ctr; i++){
- words[i] = s2.next();
- }
- return words;
- }
- catch (FileNotFoundException e){
- }
- return null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement