Advertisement
Morogn93

Reading from File java

Jul 13th, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.50 KB | None | 0 0
  1.  
  2.         public String ReadFromFile(String nameFile) {
  3.  
  4.             String textFromFile = "";
  5.  
  6.             try {
  7.                 Scanner sc = new Scanner(new File(nameFile));
  8.  
  9.                 while(sc.hasNextLine()) {
  10.                     textFromFile += sc.nextLine()+ " ";
  11.                 }
  12.                 sc.close();
  13.  
  14.             }catch (Exception e){
  15.                 System.out.println(e + "Najprawdopodobnie plik nie istnieje");
  16.             }
  17.  
  18.             return textFromFile;
  19.  
  20.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement