Рассмотрите следующий код, используя классы Nio.2. Кажется странным, что я должен вернуться в более старый файл для этой одной функции.try
{
String message = "Whatever " + Instant.now() ;
final Path path =
Files.writeString (
Files.createTempFile ( "Example_" , ".txt" ) ,
message ,
StandardCharsets.UTF_8
);
List lines = Files.readAllLines ( path );
path.toFile ( ).deleteOnExit ( ); //
return path; // Return the path for further writing.
}
catch ( IOException e )
{
throw new RuntimeException ( e );
}
Подробнее здесь: https://stackoverflow.com/questions/796 ... le-in-java