Subversion Repositories SmartDukaan

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

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