<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>file handling in java Archives -</title>
	<atom:link href="https://mitindia.in/tag/file-handling-in-java/feed/" rel="self" type="application/rss+xml" />
	<link>https://mitindia.in/tag/file-handling-in-java/</link>
	<description></description>
	<lastBuildDate>Fri, 08 Jul 2016 05:54:40 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://mitindia.in/wp-content/uploads/2023/03/cropped-android-chrome-512x512-1-32x32.png</url>
	<title>file handling in java Archives -</title>
	<link>https://mitindia.in/tag/file-handling-in-java/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>File Handling in Java</title>
		<link>https://mitindia.in/file-handling-java/</link>
		
		<dc:creator><![CDATA[SKB]]></dc:creator>
		<pubDate>Mon, 04 Jul 2016 13:22:34 +0000</pubDate>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[file handling in java]]></category>
		<guid isPermaLink="false">http://www.mitindia.in/?p=223</guid>

					<description><![CDATA[<p>File is a collection of bytes stored in secondary storage device i.e. disk. Thus, File handling is used to read, write, append or update a file without directly opening it. Types of File: Text File Binary File Text File contains only textual data. Text files may be saved in either a plain text (.TXT) format [&#8230;]</p>
<p>The post <a href="https://mitindia.in/file-handling-java/">File Handling in Java</a> appeared first on <a href="https://mitindia.in"></a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>File is a collection of bytes stored in secondary storage device i.e. disk. Thus, File handling is used to read, write, append or update a file without directly opening it.</p>
<div id="post-body-1480023860894181500" class="post-body entry-content">
<div dir="ltr">
<p>Types of File:</p>
<ul>
<li>Text File</li>
<li>Binary File</li>
</ul>
<p>Text File contains only textual data. Text files may be saved in either a plain text (.TXT) format and rich text (.RTF) format like files in our Notepad.<br />
Binary Files contains both textual data and custom binary data like font size, text color and text style etc.</p>
<p>Java File Handling program to input data to an existing file, else it will create a new one and adds contents in it. [following program demonstrate the same]</p>
<pre>import java.io.File;
import java.io.FileWriter;
import java.io.BufferedWriter;
import java.io.IOException;
 
public class FileApp 
{
public static void main( String args[] )
 {  

try
{
String data = " 1234567890 hello to java file";
 File file =new File("temp.txt");

 if(!file.exists())
{
file.createNewFile();
}
 
FileWriter fileWritter = new FileWriter(file.getName(),true);
BufferedWriter bufferWritter = new BufferedWriter(fileWritter);
bufferWritter.write(data);
bufferWritter.close();
System.out.println("Done");
}
catch(IOException e){ }
}
}</pre>
<p>Java File Handling program to delete an existing file stored on the disk.</p>
<pre>import java.io.File;
public class FileDel
{
public static void main(String[] args)
{   
try
{
File file = new File("c:\\temp.txt");
if(file.delete())
{
System.out.println(file.getName() + " is deleted!");
}
else
{
System.out.println("Delete operation is failed.");
}
}
catch(Exception e){ e.printStackTrace(); 
}
}
}</pre>
<p>Java File Handling program to test whether the file or folder exists or not in the specified location.</p>
<pre>import java.io.*;
public class FileExt
{
public static void main(String args[])
{
File file=new File("C:/temp.txt");
boolean exists = file.exists();
if(exists) 
{
System.out.println("File or Directory exist.");
}
else
{
System.out.println("File or Directory does not exists.");
}
}
}</pre>
<p>Java File Handling program to read contents from the existing file.</p>
<pre>import java.io.*;
class FileRead 
{
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("temp5.txt");

DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));

  String strLine;
  while ((strLine = br.readLine()) != null) 
{
System.out.println (strLine);
}

 in.close();
  }catch (Exception e){
  System.err.println("Error: " + e.getMessage());
  }
  }
}</pre>
<p>Java File Handling program to check Existing FILE SIZE</p>
<pre>import java.io.*;
public class FileSize 
{
public static void main(String args[])
{
File file = new File("guru_cv1.doc");
long filesize = file.length();
long filesizeInKB = filesize / 1024;
System.out.println("Size of File is: "  + filesizeInKB + " KB");
}
}</pre>
<p>Java File Handling program to input data into an existing file.</p>
<pre>import java.io.*;
class FileTest
{
public static void main(String args[])
{
try
{
FileOutputStream fout=new FileOutputStream("temp5.txt");
DataInputStream in=new DataInputStream(System.in);
String s;
System.out.print("Enter any string:");
s=in.readLine();
byte b[]=s.getBytes();
fout.write(b) ;
fout.close();
System.out.println("Data was successfully entered into the file!");
}
catch(Exception e) {}
}
}</pre>
</div>
</div>
<p><a class="a2a_button_whatsapp" href="https://www.addtoany.com/add_to/whatsapp?linkurl=https%3A%2F%2Fmitindia.in%2Ffile-handling-java%2F&amp;linkname=File%20Handling%20in%20Java" title="WhatsApp" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fmitindia.in%2Ffile-handling-java%2F&amp;linkname=File%20Handling%20in%20Java" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fmitindia.in%2Ffile-handling-java%2F&#038;title=File%20Handling%20in%20Java" data-a2a-url="https://mitindia.in/file-handling-java/" data-a2a-title="File Handling in Java"><img src="https://static.addtoany.com/buttons/favicon.png" alt="Share"></a></p><p>The post <a href="https://mitindia.in/file-handling-java/">File Handling in Java</a> appeared first on <a href="https://mitindia.in"></a>.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
