1private ArrayList<String> readFileLines(String filepath) throws FileNotFoundException, IOException{
2 File fp = new File(filepath);
3 FileReader fr = new FileReader(fp);
4 BufferedReader br = new BufferedReader(fr);
5
6 ArrayList<String> lines = new ArrayList<>();
7 String line;
8 while((line = br.readLine()) != null) { lines.add(line); }
9
10 fr.close();
11 return lines;
12}
1# attempt #1
2f = open("Bills.txt", "w")
3f.write("\n".join(map(lambda x: str(x), bill_List)))
4f.close()
5
6
7# attempt #2
8# Open a file in write mode
9f = open('Bills.txt', 'w')
10for item in bill_List:
11f.write("%s\n" % item)
12# Close opend file
13f.close()
14
15# attempt #3
16
17with open('Bills.txt', 'w') as f:
18for s in bill_List:
19 f.write(s + '\n')
20
21with open('Bills.txt', 'r') as f:
22bill_List = [line.rstrip('\n') for line in f]
23
24# attempt #4
25with open('Bills.txt', 'w') as out_file:
26out_file.write('\n'.join(
27 bill_List))