Total members 10259 | Gratitudes |It is currently Mon May 21, 2012 4:06 pm Login / Join Codemiles


All times are UTC [ DST ]




Post new topic Reply to topic  Quick reply  [ 1 post ] 
Author Topic
 Topic subject: Multithreaded File Reading
PostPosted: Fri Oct 17, 2008 1:27 pm 
Offline
Beginner
User avatar

Joined: Sun May 25, 2008 5:34 pm
Posts: 95
Has thanked: 2 time
Have thanks: 1 time

* Project Name:   Multithreaded File Reading
* Type:   Multithreading
* Technology:  Java
* IDE:   Any
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.");
        }
}


TOP
 Profile Send private message  
Reply with quote  
Post new topic Reply to topic Quick reply  [ 1 post ] 
Quick reply


  


 Similar topics
 Image Insert in Excel File Using POI
 ASP file structure
 Search records from text file
 error closing file matlab save
 Java Object Reading
 How to download any file in jsp.
 read php file in asp and display it as html
 javascript read file
 How to make PHP form data saved into txt file
 file exists in upper level folder link

All times are UTC [ DST ]


Users browsing similar posts

Users browsing this forum: No registered users and 1 guest



Jump to:  
Previous Topic | Next Topic 




Home
General Talks
Finished Projects
Code Library
Games
Tutorials

Java
C/C++
C-sharp
php
Script
JSP/Servlets
Ajax
ASP/ASP.net
Google SEO
Database
Communications
Phpbb3 styles
Photoshop tutorials
Flash tutorials
Find a job






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team