Total members 11894 |It is currently Thu Nov 21, 2024 1:27 pm Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka






* Project Name:   Multithreaded File Reading
* Type:   Multithreading
* Technology:  Java
* IDE:   Any
 Description:   This code is an example of how you can read File(I/O) with using threading.
java code
import java.io.*;
import java.lang.*;
class MultiThreadedFileRead extends Thread
{
InputStream in;
MultiThreadedFileRead(String fname) throws Exception
{
in=new FileInputStream(fname);
this.start();
}
public void run()
{
int i=0;
while(i!=-1)
{
try
{
i=in.read();
System.out.print((char)i);
}catch(Exception e){}
}
try
{
in.close();
}catch(Exception e){}
}
public static void main(String a[]) throws Exception
{
int n=2;
System.out.print("Enter the number of files : ");
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
try
{
n=Integer.parseInt(br.readLine());
}catch(Exception e){}
MultiThreadedFileRead fr[]=new MultiThreadedFileRead[n];
long tim;
tim=System.currentTimeMillis();
for(int i=0;i<n;i++)
fr[i]=new MultiThreadedFileRead(a[i]);
for(int i=0;i<n;i++)
{
try
{
fr[i].join();
}catch(Exception e){}
}
System.out.println("Time Required : "+(System.currentTimeMillis()-tim)+" miliseconds.");
}
}




_________________
Please recommend my post if you found it helpful


Author:
Beginner
User avatar Posts: 95
Have thanks: 2 time
Post new topic Reply to topic  [ 1 post ] 

  Related Posts  to : Multithreaded File Reading
 Reading the all file in php     -  
 Reading file with integers     -  
 Reading and Writing To text file     -  
 Reading selected data from a source file     -  
 Reading a File Line by Line in php     -  
 Encrypt/Decrypt a file from source file to target file.     -  
 help reading greyscaled image !     -  
 Parsing and Reading RSS feeds     -  
 Reading a Specific Character in php     -  
 Java Object Reading     -  



Topic Tags

Java Threads, Java Files and I/O
cron






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com