Java: работа с файлами - запись, чтение, удаление

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. :

java file handling




, – . , File . FileInputStream .

FileOutputStream :

java android




FileInputStream, “append”, true , , , false – , .. .





:

java file handling example




FileInputStream file1.txt read(). . while write FileOutputStream, file2.txt. close.

FileReader FileWriter

, , . FileReader FileWriter Java. , . Reader Writer , .

FileReader FileWriter :

java work with files and folders




, . , , . Java . :

java file handling




, . , , read , write . write int, 16 , Java .

, Java. , Java Android, .




All Articles