Advertisement
Guest User

code

a guest
Dec 22nd, 2012
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.78 KB | None | 0 0
  1. import java.io.*;
  2. import java.util.*;
  3. import java.lang.*;
  4. import java.io.FileNotFoundException;
  5. import java.io.IOException;
  6.  
  7.  
  8. public class loadFile {
  9.     //Load a file into a string
  10.     // filePath example: "C:\\temp\\myFile.txt"
  11.     public String loadFile(String filePath)throws FileNotFoundException, IOException
  12.     {
  13.        // Load the file
  14.      StringBuilder stringBuilder = new StringBuilder();
  15.      BufferedReader bufferedReader = new BufferedReader(new FileReader(filePath) );
  16.        try
  17.        {
  18.        String line = null;
  19.        while( ( line = bufferedReader.readLine()) != null)
  20.           stringBuilder.append(line + System.getProperty("line.separator") );
  21.  
  22.        bufferedReader.close();
  23.        
  24.        }
  25.        catch(IOException e){
  26.             e.printStackTrace();
  27.     }
  28.  
  29.        return stringBuilder.toString();
  30. }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement