I have tried to create a file using the code given below:
  Import java.io .File; Public class DeleteEvidence {Public Static Zero Main (String [] Args) {File Proof = New File ("Cooked Books. Txt");    However, the file  cookedBooks.txt  is not available anywhere on my computer. I am very new to this, so I am having trouble understanding other threads about similar problems.     
  You successfully created an example of class  file  Creating actual files in is very different from. Examples of class    file  are used to refer files to disk, for example, you can use them in many things:   -  Check whether files or directories exist;  
 -  Create / delete / rename files or directories; And  
 -  Open "Stream" to write data in files.   
 To create a file in your hard disk and write some data, you can use it example,  FileOutputStream . Public class AnExample {Public static throws throttle zero main (string ... args) (last file file = new file ("file.dat"); Try (FileOutputStream fos = new FileOutputStream; DataOutputStream Out = New DataOutputStream (fos)) {out.writeInt (42);}}    here,  fos  in  FileOutputStream In an example of , which writes  OutputStream , all the bytes are written in an underlying file on the disk.   Then, I have the  DataOutputStr Eam  will create that file around that file - FileOutputStream : In this way, we have only one possibility by using the bytes and byte arrays (which is  FileOutputStream  ).   Finally, four bytes of data are written to the file: four bytes represent the integer  42 . Open this file on the text editor, you will see the garbage because above Code '4' and '2' are not written in the code.   Another possibility:  Outputstream Whiters , which will give you an example of  writer  that can be used to write text (non-binary) file Is: Public class AnExample {Public static zero main throws throws (string ... args) (last file file = new file ("file.txt"); Try (FileOutputStream fos = New FileOutputStream (File); OutputStreamWriter Out = New OutputStream Water (fos, StandardCharsets.UTF_8)) {out.write ("You A You can read with text editor. ");}}}    Here, you can open file  file.txt  on the text editor and send it Can read.   
 
 
No comments:
Post a Comment