41
41
import java .io .Writer ;
42
42
import java .nio .charset .Charset ;
43
43
import java .nio .charset .StandardCharsets ;
44
+ import java .nio .file .Files ;
45
+ import java .nio .file .Path ;
44
46
import java .sql .BatchUpdateException ;
45
47
import java .sql .Connection ;
46
48
import java .sql .DriverManager ;
@@ -92,6 +94,14 @@ private static String printable(final String s) {
92
94
93
95
private final String recordSeparator = CSVFormat .DEFAULT .getRecordSeparator ();
94
96
97
+ private File createTempFile () throws IOException {
98
+ return createTempPath ().toFile ();
99
+ }
100
+
101
+ private Path createTempPath () throws IOException {
102
+ return Files .createTempFile (getClass ().getName (), ".csv" );
103
+ }
104
+
95
105
private void doOneRandom (final CSVFormat format ) throws Exception {
96
106
final Random r = new Random ();
97
107
@@ -1543,7 +1553,7 @@ public void testPrintRecordsWithResultSetOneRow() throws IOException, SQLExcepti
1543
1553
1544
1554
@ Test
1545
1555
public void testPrintToFileWithCharsetUtf16Be () throws IOException {
1546
- final File file = File . createTempFile (getClass (). getName (), ".csv" );
1556
+ final File file = createTempFile ();
1547
1557
try (final CSVPrinter printer = CSVFormat .DEFAULT .print (file , StandardCharsets .UTF_16BE )) {
1548
1558
printer .printRecord ("a" , "b\\ c" );
1549
1559
}
@@ -1552,7 +1562,7 @@ public void testPrintToFileWithCharsetUtf16Be() throws IOException {
1552
1562
1553
1563
@ Test
1554
1564
public void testPrintToFileWithDefaultCharset () throws IOException {
1555
- final File file = File . createTempFile (getClass (). getName (), ".csv" );
1565
+ final File file = createTempFile ();
1556
1566
try (final CSVPrinter printer = CSVFormat .DEFAULT .print (file , Charset .defaultCharset ())) {
1557
1567
printer .printRecord ("a" , "b\\ c" );
1558
1568
}
@@ -1561,11 +1571,11 @@ public void testPrintToFileWithDefaultCharset() throws IOException {
1561
1571
1562
1572
@ Test
1563
1573
public void testPrintToPathWithDefaultCharset () throws IOException {
1564
- final File file = File . createTempFile ( getClass (). getName (), ".csv" );
1565
- try (final CSVPrinter printer = CSVFormat .DEFAULT .print (file . toPath () , Charset .defaultCharset ())) {
1574
+ final Path file = createTempPath ( );
1575
+ try (final CSVPrinter printer = CSVFormat .DEFAULT .print (file , Charset .defaultCharset ())) {
1566
1576
printer .printRecord ("a" , "b\\ c" );
1567
1577
}
1568
- assertEquals ("a,b\\ c" + recordSeparator , FileUtils . readFileToString (file , Charset .defaultCharset ()));
1578
+ assertEquals ("a,b\\ c" + recordSeparator , new String ( Files . readAllBytes (file ) , Charset .defaultCharset ()));
1569
1579
}
1570
1580
1571
1581
@ Test
0 commit comments