

{"id":15280,"date":"2018-05-09T05:16:37","date_gmt":"2018-05-09T05:16:37","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=15280"},"modified":"2026-05-28T14:18:19","modified_gmt":"2026-05-28T08:48:19","slug":"file-handling-in-java","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/file-handling-in-java\/","title":{"rendered":"File Handling in Java (Java FileReader &amp; FileWriter) With Example"},"content":{"rendered":"<p>File handling means performing various functions on a file, like reading, writing, editing, etc. Java provides us with a provision to perform these operations through programming, without actually having to open the file. In this article, we will take a look at all those properties of Java programming and how to perform these operations using Java.<\/p>\n<h3>Java File Handling<\/h3>\n<p>Java provides us with library classes and various methods to perform file handling easily. All these methods are present in the File Class of the java.io package.<br \/>\nSo, first of all, before starting these programs, we need to import this package and the file class.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">import java.io.File;\r\n<\/pre>\n<p>Java uses streams to perform file-related operations. Let us understand the concept of stream first.<\/p>\n<h3>Stream in Java<\/h3>\n<p>Stream is a concept of Java that pipelines a sequence of objects to obtain the desired result. A stream can not be called a data structure; it just takes input from the collection of I\/O.<\/p>\n<p>A stream can be classified into two types: Byte Stream and Character Stream.<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/stream-in-java.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-108865\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/stream-in-java.webp\" alt=\"stream in java\" width=\"875\" height=\"404\" \/><\/a><\/p>\n<h4>Byte Stream<\/h4>\n<p>The byte stream deals mainly with byte data. We know that one byte is equal to eight bits. Thus, this stream mainly deals with 8 bits of data. This stream performs an Input-output operation per 8 bits of data.<\/p>\n<p>The byte stream contains two stream classes, Input Stream classes and Output Stream Classes.<\/p>\n<p><strong>1. Input Stream Classes:<\/strong> This stream helps take input(Read Data) from the collection in I\/O File.<\/p>\n<p><strong>2. Output Stream Classes:<\/strong> This stream helps to give output(Write Data) into the collection in an I\/O File.<\/p>\n<p>The most commonly used Input and Output Stream Classes are FileInputStream and FileOutputStream.<\/p>\n<p>We will see how to use them later while discussing the various file operations.<\/p>\n<h4>Character Stream<\/h4>\n<p>There is also Character Stream, which allows I\/O operation on 16bit of Unicode data at a time. Character Stream takes 2 bytes of data at a time. It is faster as it can take double the intake as compared to a byte stream. Character streams usually use Byte Stream classes to implement operations.<\/p>\n<p>The two main classes used in Character Stream are FileReader and FileWriter.<\/p>\n<p>We will see how to use them later while discussing the various file operations.<\/p>\n<h3>The methods present in File class(java.io.File)<\/h3>\n<p>The file class contains various methods that perform various important tasks. Let us discuss them through this easy-to-comprehend table.<\/p>\n<table>\n<tbody>\n<tr>\n<td><b>SL. No.<\/b><\/td>\n<td><b>Method<\/b><\/td>\n<td><b>Return Type<\/b><\/td>\n<td><b>Description<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">1.<\/span><\/td>\n<td><span style=\"font-weight: 400\">canRead()<\/span><\/td>\n<td><span style=\"font-weight: 400\">Boolean<\/span><\/td>\n<td><span style=\"font-weight: 400\">This method checks whether the file is readable or not.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">2.<\/span><\/td>\n<td><span style=\"font-weight: 400\">createNewFile()<\/span><\/td>\n<td><span style=\"font-weight: 400\">Boolean<\/span><\/td>\n<td><span style=\"font-weight: 400\">This method creates a new file in the desired path. The file created is generally empty.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">3.<\/span><\/td>\n<td><span style=\"font-weight: 400\">canWrite()<\/span><\/td>\n<td><span style=\"font-weight: 400\">Boolean<\/span><\/td>\n<td><span style=\"font-weight: 400\">This method checks whether the file is writable or not,i.e, not a read-only file.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">4.<\/span><\/td>\n<td><span style=\"font-weight: 400\">exists()<\/span><\/td>\n<td><span style=\"font-weight: 400\">Boolean<\/span><\/td>\n<td><span style=\"font-weight: 400\">This method verifies if the file asked for is present or not in the directory.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">5.<\/span><\/td>\n<td><span style=\"font-weight: 400\">delete()<\/span><\/td>\n<td><span style=\"font-weight: 400\">Boolean<\/span><\/td>\n<td><span style=\"font-weight: 400\">This method is used to delete a file from the directory.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">6.<\/span><\/td>\n<td><span style=\"font-weight: 400\">getName()<\/span><\/td>\n<td><span style=\"font-weight: 400\">String<\/span><\/td>\n<td><span style=\"font-weight: 400\">This method helps us find the name of a particular file in the directory.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">7.<\/span><\/td>\n<td><span style=\"font-weight: 400\">getAbsolutePath()<\/span><\/td>\n<td><span style=\"font-weight: 400\">String<\/span><\/td>\n<td><span style=\"font-weight: 400\">This method returns the absolute path of the given file.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">8.<\/span><\/td>\n<td><span style=\"font-weight: 400\">length()<\/span><\/td>\n<td><span style=\"font-weight: 400\">Long<\/span><\/td>\n<td><span style=\"font-weight: 400\">This method returns the size of a file in bytes.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">9.<\/span><\/td>\n<td><span style=\"font-weight: 400\">list()<\/span><\/td>\n<td><span style=\"font-weight: 400\">String[]<\/span><\/td>\n<td><span style=\"font-weight: 400\">This method returns an array, listing all the files present in the present working directory(PWD).<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">10.<\/span><\/td>\n<td><span style=\"font-weight: 400\">mkdir()<\/span><\/td>\n<td><span style=\"font-weight: 400\">Boolean<\/span><\/td>\n<td><span style=\"font-weight: 400\">This Method stands for making a directory. This method helps us create a new directory(Not a file).<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Now we will discuss the different operations for File Handling in Java using both byte streams and character streams.<\/p>\n<h3>Java File Operation<\/h3>\n<h4>1. Creating a File in Java<\/h4>\n<p>We can use the createNewFile() method to create a new file using Java. If the method returns true, the file has been created successfully, the file creation was unsuccessful.<\/p>\n<p><strong>Code to explain the working of createNewFile():<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">package com.DataFlair.FileHandling;\r\nimport java.io.File;   \r\nimport java.io.IOException;  \r\npublic class CreatingNewFile\r\n{\r\n    public static void main(String args[])\r\n    {  \r\n          try {  \r\n                   File fcreate = new File(\"G:\\\\Internship\\\\File Handling\\\\NewFile.txt\");   \r\n                    if (fcreate.createNewFile()) {  \r\n                        System.out.println(\"File \" + fcreate.getName() + \" is created successfully.\");\r\n                    }\r\n                     else {  \r\n                              System.out.println(\"File is already exist in the directory.\"); \r\n                            }\r\n                            } catch (IOException exception) {  \r\n                          System.out.println(\"An unexpected error is occurred.\");  \r\n                          exception.printStackTrace();  \r\n              }   \r\n}\r\n}\r\n<\/pre>\n<p><strong>The output of the above code:<\/strong><\/p>\n<div class=\"code-output\">File NewFile.txt is created successfully.<\/div>\n<p>The File named NewFile.txt was created in the given path. The Try-Catch block is used to handle errors if there is already a file with the same name.<\/p>\n<h4>2. Java Get File Information<\/h4>\n<p>When we want to fetch the information about the file, we use these methods. Generally, when we want to perform only a read-only operation and not the updation operation, we use such types of methods. For example, if we want to know about the size of the file, whether the file is present in a system, or not. If we want to know about the editing access of the file, such that we can write into the file or not, that can also be checked by getting file information. It generally restricts editing access to a file.<\/p>\n<p>Through the various methods given in the File class, we are able to get all sorts of information about a file. These methods can give information like name, length, path, read-only, write-only, etc.<\/p>\n<p><strong>Code to Explain Methods to get various file information:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">package com.DataFlair.FileHandling;\r\nimport java.io.File;  \r\npublic class FileInformation\r\n{\r\n      public static void main(String[] args) {   \r\n        File finfo = new File(\"G:\\\\Internship\\\\File Handling\\\\NewFile.txt\");  \r\n        if (finfo.exists()) {  \r\n             System.out.println(\"The name of the file is: \" + finfo.getName());  \r\n             System.out.println(\"The absolute path of the file is: \" + finfo.getAbsolutePath());\r\n             System.out.println(\"Is file writeable: \" + finfo.canWrite());\r\n             System.out.println(\"Is file readable: \" + finfo.canRead());\r\n             System.out.println(\"The size of the file is: \" + finfo.length());\r\n            } else {  \r\n            System.out.println(\"The file does not exist.\");  \r\n        }  \r\n    }  \r\n}  \r\n<\/pre>\n<p><strong>The output of the above code:<\/strong><\/p>\n<div class=\"code-output\">The name of the file is: NewFile.txt<br \/>\nThe absolute path of the file is: G:\\Internship\\File Handling\\NewFile.txt<br \/>\nIs file writeable: true<br \/>\nIs file readable: true<br \/>\nThe size of the file is: 0<\/div>\n<p>The above class uses methods like getName(), getAbsolutePath(), canWrite(),canRead(),length(), to get various information about the file NewFile.txt.<br \/>\nWe use the try-catch block to check if the file exists or not.<\/p>\n<h4>3. Write into a Java File<\/h4>\n<p>We can write into a file using the byte stream class OutputStreamWriter or the character stream class FileWriter.<\/p>\n<p>Let us discuss them individually.<\/p>\n<h5>Using OutputStreamWriter<\/h5>\n<p>We can use the OutputStreamWriter class of the byte stream to write into a file. This class writes 8 bits of data at a time.<br \/>\nWe should always remember to close the stream, or else it might create a memory dump.<\/p>\n<p><strong>Code to Write into a File using OutputStreamWriter:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">package com.DataFlair.FileHandling;\r\nimport java.io.FileOutputStream;\r\nimport java.io.OutputStream;\r\nimport java.io.OutputStreamWriter;\r\nimport java.io.Writer;\r\npublic class ByteStreamWrite\r\n{\r\n       public static void main(String[] args) {  \r\n        try { \r\n            OutputStream fwrite = new FileOutputStream(\"G:\\\\Internship\\\\File Handling\\\\NewFile.txt\");  \r\n            Writer fwriteWriter = new OutputStreamWriter(fwrite);  \r\n            fwriteWriter.write(\"Writing Using OutputStreamWriter!!!\");  \r\n            fwriteWriter.close();  \r\n        } catch (Exception e) {  \r\n            e.getMessage();  \r\n        }  \r\n    }  \r\n}  \r\n<\/pre>\n<h5>Using Java FileWriter<\/h5>\n<p>The character stream contains the FileWriter class, which can write 16 bits of data at a time into a file. This is a much quicker technique compared to OutputStreamWriter, as 16 bits of data are written at a time.<\/p>\n<p><strong>Code to Write into a file using FileWriter:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">package com.DataFlair.FileHandling;\r\nimport java.io.FileWriter;\r\nimport java.io.IOException;  \r\npublic class CharacterStreamWrite\r\n{\r\n    public static void main(String[] args) {  \r\n    try {  \r\n        FileWriter fwrite = new FileWriter(\"G:\\\\Internship\\\\File Handling\\\\NewFile.txt\");  \r\n        fwrite.write(\"Written using FileWriter!!!\");   \r\n        fwrite.close(); \r\n        } catch (IOException e) {  \r\n        System.out.println(\"Error While Writing!!!\");  \r\n        e.printStackTrace();  \r\n        }  \r\n    }  \r\n}  \r\n<\/pre>\n<h4>4. Read from a Java File<\/h4>\n<p>Similarly to writing, we can read a file using a byte stream and a character stream. In the byte stream, we use InputStreamReader, and in the character stream, we have FileReader to read the contents of a file.<\/p>\n<h5>Using Java InputStreamReader<\/h5>\n<p>The InputStreamReader class is part of the Java byte stream; it can read 8 bits of data at a time. After reading the data, the file object should always be closed.<\/p>\n<p><strong>Code to understand reading using InputStreamReader:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">package com.DataFlair.FileHandling;\r\nimport java.io.InputStream;\r\nimport java.io.FileInputStream;\r\nimport java.io.Reader;\r\nimport java.io.InputStreamReader;\r\npublic class ByteStreamRead\r\n{\r\n       public static void main(String[] args) {  \r\n        try  {  \r\n            InputStream fread = new FileInputStream(\"G:\\\\Internship\\\\File Handling\\\\NewFile.txt\");  \r\n            Reader freader = new InputStreamReader(fread);  \r\n            int data = freader.read();  \r\n            while (data != -1) {  \r\n                System.out.print((char) data);  \r\n                data = freader.read();  \r\n            }  \r\n        } catch (Exception e) {  \r\n            e.printStackTrace();  \r\n        }  \r\n    }  \r\n}\r\n<\/pre>\n<p><strong>The output of the above code:<\/strong><\/p>\n<div class=\"code-output\">Written using FileWriter!!!<\/div>\n<p>This was the content of the file after executing the previous code, so the printed output gives the content of the file properly.<\/p>\n<h5>Using java FileReader<\/h5>\n<p>The FileReader is a class of the character stream, thus it reads 16 bits of data at a time. It is faster than InputStreamReader.<\/p>\n<p><strong>Code to understand reading a file using FileReader:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">package com.DataFlair.FileHandling;\r\nimport java.io.FileReader; \r\npublic class CharacterStreamRead\r\n{\r\n    public static void main(String args[])throws Exception\r\n    {    \r\n         FileReader fr=new FileReader(\"G:\\\\Internship\\\\File Handling\\\\NewFile.txt\");    \r\n         int i;    \r\n         while((i=fr.read())!=-1)    \r\n              System.out.print((char)i);    \r\n         fr.close();    \r\n    }    \r\n}\r\n<\/pre>\n<p><strong>The output of the above code:<\/strong><\/p>\n<div class=\"code-output\">Written using FileWriter!!!<\/div>\n<p>We can see that the code is much shorter, simpler, and faster. This is the reason why programmers prefer to use the character stream instead of the byte stream.<\/p>\n<h4>5. Deleting a File in Java<\/h4>\n<p>A file can be deleted using Java through the method delete(). We do not need to close the file, as we do not use any reader or writer classes.<\/p>\n<p><strong>Code to Delete File using delete():<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">package com.DataFlair.FileHandling;\r\nimport java.io.File;   \r\npublic class DeleteFile\r\n{\r\n     public static void main(String[] args)\r\n     {  \r\n        File fdel = new File(\"G:\\\\Internship\\\\File Handling\\\\NewFile.txt\");   \r\n        if (fdel.delete())\r\n        { \r\n            System.out.println(fdel.getName()+ \" is deleted successfully.\");  \r\n        }\r\n        else \r\n        {  \r\n            System.out.println(\"Could Not Delete File\");  \r\n        }\r\n    }\r\n}\r\n<\/pre>\n<p><strong>The output of the above code:<\/strong><\/p>\n<div class=\"code-output\">NewFile.txt was deleted successfully.<\/div>\n<p>As we can see from the above snapshot, the file has been deleted from the directory.<\/p>\n<h3>Conclusion<\/h3>\n<p>So, in this article, we saw file handling in Java. This is a very important concept as it enables us to automate a file\u2019s content using a program that could save us a lot of time. We saw how to create, read, write, and delete a file from our system.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>File handling means performing various functions on a file, like reading, writing, editing, etc. Java provides us with a provision to perform these operations through programming, without actually having to open the file. In&#46;&#46;&#46;<\/p>\n","protected":false},"author":5,"featured_media":108863,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[32],"tags":[20760,20759,20758,20757],"class_list":["post-15280","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-java","tag-file-handling-in-java-with-example","tag-filereader-in-java","tag-filewriter-in-java","tag-java-file-handling"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>File Handling in Java (Java FileReader &amp; FileWriter) With Example - DataFlair<\/title>\n<meta name=\"description\" content=\"File Handling in Java permits us to create, read, update, delete files stored on local file system. Learn to create, read, write files.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/data-flair.training\/blogs\/file-handling-in-java\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"File Handling in Java (Java FileReader &amp; FileWriter) With Example - DataFlair\" \/>\n<meta property=\"og:description\" content=\"File Handling in Java permits us to create, read, update, delete files stored on local file system. Learn to create, read, write files.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/file-handling-in-java\/\" \/>\n<meta property=\"og:site_name\" content=\"DataFlair\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DataFlairWS\/\" \/>\n<meta property=\"article:published_time\" content=\"2018-05-09T05:16:37+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-05-28T08:48:19+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/file-handling-in-java.webp\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/webp\" \/>\n<meta name=\"author\" content=\"DataFlair Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:site\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DataFlair Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"File Handling in Java (Java FileReader &amp; FileWriter) With Example - DataFlair","description":"File Handling in Java permits us to create, read, update, delete files stored on local file system. Learn to create, read, write files.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/data-flair.training\/blogs\/file-handling-in-java\/","og_locale":"en_US","og_type":"article","og_title":"File Handling in Java (Java FileReader &amp; FileWriter) With Example - DataFlair","og_description":"File Handling in Java permits us to create, read, update, delete files stored on local file system. Learn to create, read, write files.","og_url":"https:\/\/data-flair.training\/blogs\/file-handling-in-java\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2018-05-09T05:16:37+00:00","article_modified_time":"2026-05-28T08:48:19+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/file-handling-in-java.webp","type":"image\/webp"}],"author":"DataFlair Team","twitter_card":"summary_large_image","twitter_creator":"@DataFlairWS","twitter_site":"@DataFlairWS","twitter_misc":{"Written by":"DataFlair Team","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/file-handling-in-java\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/file-handling-in-java\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/7f83c342f5d1632d6f7b4b0b0f447823"},"headline":"File Handling in Java (Java FileReader &amp; FileWriter) With Example","datePublished":"2018-05-09T05:16:37+00:00","dateModified":"2026-05-28T08:48:19+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/file-handling-in-java\/"},"wordCount":1321,"commentCount":5,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/file-handling-in-java\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/file-handling-in-java.webp","keywords":["File Handling in Java with Example","FileReader in Java","FileWriter in Java","Java File Handling"],"articleSection":["Java Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/file-handling-in-java\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/file-handling-in-java\/","url":"https:\/\/data-flair.training\/blogs\/file-handling-in-java\/","name":"File Handling in Java (Java FileReader &amp; FileWriter) With Example - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/file-handling-in-java\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/file-handling-in-java\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/file-handling-in-java.webp","datePublished":"2018-05-09T05:16:37+00:00","dateModified":"2026-05-28T08:48:19+00:00","description":"File Handling in Java permits us to create, read, update, delete files stored on local file system. Learn to create, read, write files.","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/file-handling-in-java\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/file-handling-in-java\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/file-handling-in-java\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/file-handling-in-java.webp","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/file-handling-in-java.webp","width":1200,"height":628,"caption":"file handling in java"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/file-handling-in-java\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"Java Tutorials","item":"https:\/\/data-flair.training\/blogs\/category\/java\/"},{"@type":"ListItem","position":3,"name":"File Handling in Java (Java FileReader &amp; FileWriter) With Example"}]},{"@type":"WebSite","@id":"https:\/\/data-flair.training\/blogs\/#website","url":"https:\/\/data-flair.training\/blogs\/","name":"DataFlair","description":"Learn Today. Lead Tomorrow.","publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/data-flair.training\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/data-flair.training\/blogs\/#organization","name":"DataFlair","url":"https:\/\/data-flair.training\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","width":106,"height":48,"caption":"DataFlair"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DataFlairWS\/","https:\/\/x.com\/DataFlairWS","https:\/\/www.linkedin.com\/company\/dataflair-web-services-pvt-ltd\/","https:\/\/www.youtube.com\/user\/DataFlairWS"]},{"@type":"Person","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/7f83c342f5d1632d6f7b4b0b0f447823","name":"DataFlair Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","caption":"DataFlair Team"},"description":"DataFlair Team creates expert-level guides on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our goal is to empower learners with easy-to-understand content. Explore our resources for career growth and practical learning.","url":"https:\/\/data-flair.training\/blogs\/author\/dfteam1\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/15280","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=15280"}],"version-history":[{"count":13,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/15280\/revisions"}],"predecessor-version":[{"id":148447,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/15280\/revisions\/148447"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/108863"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=15280"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=15280"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=15280"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}