Сообщения

Сообщения за октябрь, 2022

Lesson: File

1.1. Before Java 7, we can use the classic FileWriter and BufferedWriter to write text to file. FileWriter fw = new FileWriter( "test3.txt" ) ; BufferedWriter bw = new BufferedWriter( fw ) ; bw .write( "Salam..." ) ; bw .close() ; fw .close() ; 1.2. In Java 7, there is a new NIO class named java.nio.file.Files, and we can use Files.write() to write  both bytes and characters. Path path = Paths . get ( "test.txt" ) ; Files . write ( path , "Salam, necesen?" .getBytes()) ; List < String > list = Arrays . asList ( "a" , "b" , "c" , "d" ) ; Files . write ( Path . of ( "test2.txt" ) , list ) ; For append mode, we can define both  StandardOpenOption.CREATE  and  StandardOpenOption.APPEND . iles . write ( Path . of ( "test.txt" ) , "Hello... \n " .getBytes() , StandardOpenOption . CREATE , StandardOpenOption . APPEND ) ; In Java 7, we need to convert the  String  into a  byte[]