Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

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


Visit http://freesourcecode.blogspot.com for Thambola, Housie, Love Calculator, Friendship Calculator, FLAMES, Animations, Digital Number, Sudoku.java - Java Programmes.


/***********************************************************/
Program to Print a File in Type Writing Style
- Krishnakanth Soni
[email protected]
/***********************************************************/
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


This post first appeared on Free Java Source Code !!!, please read the originial post: here

Share the post

Program Printing a Given File in Type Writing Style

×

Subscribe to Free Java Source Code !!!

Get updates delivered right to your inbox!

Thank you for your subscription

×