Advertisement
Guest User

Untitled

a guest
Apr 24th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. import java.io.File;
  2. import java.io.FileNotFoundException;
  3. import java.util.Scanner;
  4.  
  5.  
  6. public class erettsegi {
  7.  
  8. public static void main (String[] args){
  9.  
  10. //String text = readString("penztar.txt");
  11. //System.out.println(text);
  12.  
  13. String[] words = readArray("penztar.txt");
  14.  
  15. for (int i = 0; i < words.length; i++){
  16. System.out.println(words[i]);
  17.  
  18. }
  19. }
  20.  
  21.  
  22.  
  23. public static String[] readArray(String file){
  24.  
  25. int ctr = 0;
  26.  
  27. try {
  28.  
  29. @SuppressWarnings("resource")
  30. Scanner s1 = new Scanner(new File(file));
  31.  
  32.  
  33. while (s1.hasNextLine()){
  34. ctr++;
  35. s1.next();
  36. }
  37. String[] words = new String[ctr];
  38.  
  39. @SuppressWarnings("resource")
  40. Scanner s2 = new Scanner(new File(file));
  41. for (int i = 0; i < ctr; i++){
  42. words[i] = s2.next();
  43.  
  44. }
  45.  
  46. return words;
  47.  
  48. }
  49. catch (FileNotFoundException e){
  50.  
  51.  
  52. }
  53.  
  54. return null;
  55.  
  56.  
  57. }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement