Subversion Repositories SmartDukaan

Rev

Rev 2146 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2146 Rev 2453
Line 9... Line 9...
9
import java.io.FileInputStream;
9
import java.io.FileInputStream;
10
import java.io.FileNotFoundException;
10
import java.io.FileNotFoundException;
11
import java.io.IOException;
11
import java.io.IOException;
12
import java.io.InputStreamReader;
12
import java.io.InputStreamReader;
13
 
13
 
-
 
14
import org.apache.log4j.Logger;
-
 
15
 
14
/**
16
/**
15
 * Utility functions 
17
 * Utility functions 
16
 * 
18
 * 
17
 * @author rajveer
19
 * @author rajveer
18
 *
20
 *
19
 */
21
 */
20
public class FileUtils {
22
public class FileUtils {
21
	
23
	
-
 
24
	private static Logger log = Logger.getLogger(Class.class);
-
 
25
	
22
	public static String read(String filename) throws IOException  {
26
	public static String read(String filename) throws IOException {
23
		
27
		
24
		File f = new File(filename);
28
		File f = new File(filename);
25
		if(!f.exists()) {
29
		if(!f.exists()) {
26
			System.out.println(filename + " - does not exist");
30
			throw new FileNotFoundException(filename + " - does not exist");
27
			throw new FileNotFoundException();
-
 
28
		}
31
		}
29
		
32
		
30
		StringBuilder textString = new StringBuilder();
33
		StringBuilder textString = new StringBuilder();
31
		FileInputStream fis = null;
34
		FileInputStream fis = null;
32
		try {
35
		try {
Line 34... Line 37...
34
			BufferedReader br = new BufferedReader(new InputStreamReader(fis));
37
			BufferedReader br = new BufferedReader(new InputStreamReader(fis));
35
			String line;
38
			String line;
36
			while((line = br.readLine()) != null){
39
			while((line = br.readLine()) != null){
37
				textString.append(line+"\n");
40
				textString.append(line+"\n");
38
			}
41
			}
39
		} catch (IOException e) {
-
 
40
			e.printStackTrace();
-
 
41
			throw e;
-
 
42
		}
-
 
43
		finally {
42
		} finally {
44
			if(fis != null) {
43
			if(fis != null)
45
				fis.close();
44
				fis.close();
46
			}
-
 
47
		}
45
		}
48
		System.out.println("Reading complete");
46
		log.debug("Reading " + filename + " completed");
49
		return textString.toString();
47
		return textString.toString();
50
	}
48
	}
51
	
49
	
52
	
50
	
53
	/**
51
	/**