Reading the Data from the Files Using Java.

With the help of the following code you can read the data from the .txt file or the Simple TEXT file.

To make this code working i have used this code with the Applet so that With the Help of Text area you can easily view the data that reside in to the Text file and the code is as follows.

//Import all the Things

import java.applet.*;
import java.awt.TextArea;
import java.net.*;
import java.io.*;
//Declare the Class nd Extends to the apllet
public class MyApplet extends Applet {
//Declare Text area to get the Content to be Displayed
TextArea t1;
public void init()
{
t1 = new TextArea();
add(t1);
//we have used the readfile function which will deal with the File, you can define the path too
readFile(“write.txt”);
}
//Definition of the Function that we have used that will take the name of the file as the argument
public void readFile(String f) {
try {
String aLine = “”;
//getting the file
URL source = new URL(getCodeBase(), f);
BufferedReader br = new BufferedReader(new InputStreamReader(source.openStream()));
//reading the fill untill it gets over
while((aLine = br.readLine())!= null) {
//Appending the data to the Textarea
t1.append(aLine);
t1.append(“\n”);
// This will display in the console too
System.out.println(aLine);
}
br.close();
}
catch(Exception e) {
e.printStackTrace();
}
}
}
Output is as follows..
File Reader
File Reader
Thus how you can read the File in the Applet ..
Don’t you think its so simple..?
Hmm Good try this and if any problem then Tell me.
Advertisements

5 thoughts on “Reading the Data from the Files Using Java.

  1. hello!This was a really marvelous topic!
    I come from roma, I was fortunate to search your Topics in digg
    Also I get much in your website really thanks very much i will come daily

    1. hie there.. Thanks for your comments.. and ya i ll be also uploading the post regarding the speech recognization too very soon and if you have any query then feel free to ask me dear.. Ok Bye Bye C ya Take care. 🙂

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s