Google
 
Web freesourcecode.blogspot.com
Subscribe to Free Java Source Code !!!

Thursday, February 16, 2006

Program Printing a Given File in Type Writing Style

This site has been moved to http://www.99applications.com
To download code/application click the following link 99applications.com/java_programs and you can also find many c and c plus plus common programs in C & C++ section




/***********************************************************/
Program to Print a File in Type Writing Style
- Krishnakanth Soni
sonikrishnakanth@gmail.com
/***********************************************************/
Output Screen
One Charector of file is printed for the specified speed..... So output may be some animation type when you execute.....

Download API and Source Code of TypeWriter here...

import java.io.*;

public class TypeWriter
{
long typingSpeed; //in nano seconds, letter per speed
File fileToType;

public TypeWriter(){
typingSpeed = 100;
fileToType = null;
}

public void setTypingSpeed( long typingSpeed ){
this.typingSpeed = typingSpeed;
}

public void setFileToType( String fileToType ){
if( fileToType.endsWith( ".txt" ) ){
this.fileToType = new File( fileToType );
if( ! this.fileToType.exists() ){
type( "-----------\nFile Not Found.....\n\n" );
System.exit( 0 );
}
}else{
type( "-----------\nFile is Not a Text Document.......\n\n" );
}
if( this.fileToType == null ){
type( "-----------\nFile Not Set.....\n\n" );
System.exit( 0 );
}
}

public void type( String line ){
for( int i=0; i < line.length(); i++ ){
System.out.print(line.charAt(i) + "" );
try{
Thread.sleep( typingSpeed );
}catch(Exception e){}
}
}

public void startTyping(){
if( fileToType == null ){
type( "-----------\nFile Not Set.....\n\n" );
System.exit( 0 );
}
try{
System.out.println( "\n\nFile Typing Started....\n\n" );
BufferedReader br = new BufferedReader( new FileReader( fileToType ) );
String str = "";
while( (str = br.readLine() ) != null ){
type( str );
}
}catch(Exception e){}
}

public static void main( String args[] ){
TypeWriter tw = new TypeWriter();
tw.setTypingSpeed( 50 );
tw.setFileToType( args[0] );
tw.startTyping();
}
}

Home

0 Comments:

Post a Comment

<< Home