-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOutputFile.java
More file actions
36 lines (29 loc) · 989 Bytes
/
OutputFile.java
File metadata and controls
36 lines (29 loc) · 989 Bytes
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
35
36
// OuputFile.java
import java.io.PrintWriter;
import java.io.IOException;
import java.io.File;
public class OutputFile implements OutputFileInterface{
PrintWriter out;
public void open(String outputFileName){
// use a PrintWriter object to write info to a outputFileName
File file = new File(outputFileName);
try{
out = new PrintWriter(outputFileName);
out.format("%-40s %-40s %-40s %-7s %-5s %-40s",
"TITLE", "ARTIST","ALBUM", "LENGTH",
"YEAR", "ADDITIONAL_INFO");
out.println();
}
catch(Exception e){
System.out.println("Exception thrown: " + e);
}
}
// Writes the information for a single item to the file
public void writeItem(MusicTrack trackToWrite){
out.format("%-40s %-40s %-40s %-7s %-5s %-40s \n", trackToWrite.getTitle(), trackToWrite.getArtist(), trackToWrite.getAlbum(), trackToWrite.getLength(), trackToWrite.getYear(), trackToWrite.getAdditionalInfo());
}
public void close(){
out.close();
}
// closes the scanner object used
}