1 changed files with 26 additions and 0 deletions
@ -0,0 +1,26 @@ |
|||||
|
package project.utils; |
||||
|
|
||||
|
import project.bean.Movie; |
||||
|
|
||||
|
import java.io.OutputStreamWriter; |
||||
|
import java.io.FileOutputStream; |
||||
|
import java.io.IOException; |
||||
|
import java.util.List; |
||||
|
|
||||
|
public class DataStorage { |
||||
|
public static void saveToCsv(List<Movie> movies, String filePath) throws IOException { |
||||
|
// Use UTF-8 encoding to properly handle Chinese characters
|
||||
|
OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(filePath), "UTF-8"); |
||||
|
writer.write("Title,Rating,Year,Director\n"); |
||||
|
|
||||
|
for (Movie movie : movies) { |
||||
|
writer.write(String.format("%s,%.1f,%d,%s\n", |
||||
|
movie.getTitle(), |
||||
|
movie.getRating(), |
||||
|
movie.getYear(), |
||||
|
movie.getDirector())); |
||||
|
} |
||||
|
|
||||
|
writer.close(); |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue