-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileUtil.java
More file actions
34 lines (32 loc) · 1.02 KB
/
Copy pathFileUtil.java
File metadata and controls
34 lines (32 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.List;
/**
* @author Prakhar Mittal
* @version 2.0
* This class contains methods to facilitate saving a List of StartUpIdea's to a file
*/
public class FileUtil {
/**
* Traverses through the list of StartUpIdeas and saves each idea to the specified file
* @param ideas list of StartUpIdeas
* @param file file object
* @return true if successful, false if unsuccessful
*/
public static boolean saveIdeasToFile(List<StartUpIdea> ideas, File file) {
PrintWriter printWriter = null;
try {
printWriter = new PrintWriter(file);
} catch (FileNotFoundException e) {
System.out.println(e.toString());
return false;
}
for (int i = 0; i < ideas.size(); i++) {
printWriter.println((i + 1) + ":");
printWriter.println(ideas.get(i).toFullString());
}
printWriter.close();
return true;
}
}