Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
7263 anupam.sin 1
/**
2
 * 
3
 */
4
package in.shop2020.serving.utils;
5
 
6
 
7
import java.io.BufferedReader;
8
import java.io.File;
9
import java.io.FileInputStream;
10
import java.io.FileNotFoundException;
11
import java.io.IOException;
12
import java.io.InputStreamReader;
13
 
14
import org.apache.log4j.Logger;
15
 
16
/**
17
 * Utility functions 
18
 * 
19
 * @author rajveer
20
 *
21
 */
22
public class FileUtils {
23
 
24
	private static Logger log = Logger.getLogger(Class.class);
25
 
26
	public static String read(String filename) throws IOException {
27
 
28
		File f = new File(filename);
29
		if(!f.exists()) {
30
			throw new FileNotFoundException(filename + " - does not exist");
31
		}
32
 
33
		StringBuilder textString = new StringBuilder();
34
		FileInputStream fis = null;
35
		try {
36
			fis = new FileInputStream(f);
37
			BufferedReader br = new BufferedReader(new InputStreamReader(fis));
38
			String line;
39
			while((line = br.readLine()) != null){
40
				textString.append(line+"\n");
41
			}
42
		} finally {
43
			if(fis != null)
44
				fis.close();
45
		}
46
		log.debug("Reading " + filename + " completed");
47
		return textString.toString();
48
	}
49
 
50
 
51
	/**
52
	 * 
53
	 * @param filename
54
	 * @throws Exception
55
	 */
56
	public static boolean delete(String filename) throws Exception {
57
		File f = new File(filename);
58
		if(f.exists()) {
59
			return f.delete();
60
		}
61
		return true;
62
	}
63
}