<?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>read a file in java | Student Projects</title>
	<atom:link href="https://studentprojects.in/tag/read-a-file-in-java/feed/" rel="self" type="application/rss+xml" />
	<link>https://studentprojects.in</link>
	<description>Microcontroller projects, Circuit Diagrams, Project Ideas</description>
	<lastBuildDate>Fri, 02 Oct 2009 17:44:29 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.1.7</generator>
	<item>
		<title>Java program to read and display files</title>
		<link>https://studentprojects.in/software-development/java/java-programs/basic/java-program-to-read-and-display-files/</link>
					<comments>https://studentprojects.in/software-development/java/java-programs/basic/java-program-to-read-and-display-files/#comments</comments>
		
		<dc:creator><![CDATA[Editorial Team]]></dc:creator>
		<pubDate>Fri, 02 Oct 2009 17:44:29 +0000</pubDate>
				<category><![CDATA[Basic Programs]]></category>
		<category><![CDATA[programs]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[read a file in java]]></category>
		<category><![CDATA[file programming]]></category>
		<category><![CDATA[disply file numbers]]></category>
		<guid isPermaLink="false">http://studentprojects.in/?p=865</guid>

					<description><![CDATA[<p>Wtire a Java program that reads a file and displays the file on the screen, with a line number before each line.</p>
<p>The post <a href="https://studentprojects.in/software-development/java/java-programs/basic/java-program-to-read-and-display-files/">Java program to read and display files</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Write a Java program that reads a file and displays the file on the screen, with a line number before each line.</p>
<pre lang="java" escaped="true" line="1">
import java.io.*;
class linenum
{
	public static void main(String[] args)throws IOException
	{
		FileInputStream fil;
		LineNumberInputStream line;
		int i;
		try
		{
			fil=new FileInputStream(args[0]);
			line=new LineNumberInputStream(fil);
		}
		catch(FileNotFoundException e)
		{
			System.out.println("No such file found");
			return;
		}
		do
		{
			i=line.read();
			if(i=='\n')
			{
				System.out.println();
				System.out.print(line.getLineNumber()+" ");
			}
			else
				System.out.print((char)i);
		}while(i!=-1);
		fil.close();
		line.close();
	}
}
</pre>
<p><strong>Output:</strong></p>
<p>Demo.java</p>
<p>class Demo<br />
1 {<br />
2	  public static void main(java Demo beta gamma delta)<br />
3   	  {<br />
4 		int n = 1 ;<br />
5    	System.out.println(&#8220;The word is &#8221; + args[ n ] );<br />
6   	 }<br />
7 }<br />
8?</p><p>The post <a href="https://studentprojects.in/software-development/java/java-programs/basic/java-program-to-read-and-display-files/">Java program to read and display files</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://studentprojects.in/software-development/java/java-programs/basic/java-program-to-read-and-display-files/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
	</channel>
</rss>
