Java has many tools for working with files, since they serve as a data warehouse in many programs. Especially often access to files is required in Java Android. All classes for working with files are located in the java.io package, where classes for working with input and output streams are also stored. Strictly speaking, in Java, working with files occurs primarily through byte and character I / O streams. The exception in this case is the File class. We’ll start with him.
File Java class - working with files
File . , , . , : , , . , File Java.
File, : File(String , String ).
, :
- getName() – ;
- exists() – true, , false ;
- isFile() – , , ;
- isDirectory() – true, ;
- canWrite() – true, ;
- canRead() – true, ;
- setReadOnly() – ;
- length() – ;
- renameTo(File ) – . true, ;
- delete() – ( ), ;
- list() – , , ( ).
, File Java .
FileInputStream FileOutputStream
, Java -. FileInputStream FileOutputStream. InputStream OutputStream , .
FileInputStream. :
, – . , File . FileInputStream .
FileOutputStream :
FileInputStream, “append”, true , , , false – , .. .
:
FileInputStream file1.txt read(). . while write FileOutputStream, file2.txt. close.
FileReader FileWriter
, , . FileReader FileWriter Java. , . Reader Writer , .
FileReader FileWriter :
, . , , . Java . :
, . , , read , write . write int, 16 , Java .
, Java. , Java Android, .