Advertisement
StefanBashkir

Untitled

Dec 22nd, 2013
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.31 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6.  
  7. package helloworldproject;
  8. import java.io.*;
  9.  
  10. /**
  11.  *
  12.  * @author Stefan
  13.  */
  14.  public class HelloWorldProject {
  15.     public static String ReadTextFile(String FileName){
  16.         String returnValue = "";
  17.         FileReader file = null;
  18.        
  19.         try{
  20.             file = new FileReader(FileName);
  21.             BufferedReader reader = new BufferedReader(file);
  22.             String line = "";
  23.             while ((line = reader.readLine()) != null){
  24.                 returnValue += line + "\n";
  25.             }
  26.         } catch (IOException e) {
  27.             throw new RuntimeException(e);
  28.         } finally {
  29.             if (file != null){
  30.                 try {
  31.                     file.close();
  32.                 } catch (IOException e){
  33.                     // ignore
  34.                 }
  35.             }
  36.         }
  37.         return returnValue;
  38.     }
  39.    
  40.     /**
  41.      * @param args the command line arguments
  42.      */
  43.         public static void main(String[] args) {
  44.             String Desktop = System.getProperty("user.home") + "/Desktop";
  45.             System.out.println(ReadTextFile(Desktop + "/text.txt"));
  46.         }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement