|
|
Submitted by Rahimv on Wed, 08/25/2010 - 18:00
/*
* Write a program that prints last n lines of a file like Unix tail command. Program
* should take file name and number of lines to print from command line arguments. Assume
* that each line is of 100 bytes approx.
*/
import java.io.*;
class TailCommand
{
public static void main(String args[])
{
try
{
|
|
|
Submitted by Rahimv on Wed, 08/25/2010 - 17:44
/*
* Write a program which counts words and numbers in the file using StreamTokenizer. Program
* should take file name from command line argument.
*/
import java.io.*;
class StreamTokenizerDemo
{
public static void main(String args[])
{
int numberOfWords = 0;
int numberOfNumbers = 0;
try{
// create a stream tokenizer
|
|
|
Submitted by Rahimv on Wed, 08/25/2010 - 17:24
/*
* Write a program which counts number of vowels in a file. Program should take
* file name from command line argument.
*/
import java.io.*;
class CountVowels
{
public static void main(String args[])
{
int i;
int count = 0;
try
{
FileReader fr = new FileReader(args[0]);
while((i=fr.read()) != -1)
{
switch((char)i)
{
|
|
|
Submitted by Rahimv on Wed, 08/25/2010 - 17:12
/*
Create a program which prints number of lines in the file. File name
should be supplied using command line argument.
*/
import java.io.*;
class CountNumberOfLinesFile
{
public static void main(String args[])
{
try
{
FileReader fr = new FileReader(args[0]);
BufferedReader br = new BufferedReader(fr);
String line;
int count = 0;
|
|
|
Submitted by Rahimv on Wed, 08/25/2010 - 17:06
/*
* Write a program which copies file and chages all characters
* to upper case characters. Program should take source and destination file names
* from command line arguments.
*/
import java.io.*;
class CopyConvertCase
{
public static void main(String args[])
{
int i;
try
{
FileReader fr = new FileReader(args[0]);
|
|
|
Submitted by Rahimv on Wed, 08/25/2010 - 15:28
/*
* Create a program which writes binary data to a file using BufferedOutputStream. Program should take
* file name from command line argument.
*/
import java.io.*;
class BufferedOutputStreamDemo
{
public static void main(String args[])
{
try
{
FileOutputStream fos = new FileOutputStream(args[0]);
BufferedOutputStream bos = new BufferedOutputStream(fos);
|
|
|
Submitted by Rahimv on Wed, 08/25/2010 - 15:22
/*
* Create a program which reads binary file using FileInputStream. Get name of the
* file from command line argument.
*/
class FileInputStreamDemo
{
public static void main(String args[])
{
try
{
FileInputStream fis = new FileInputStream(args[0]);
int i;
while((i = fis.read())!= -1){
System.out.print(i);
}
fis.close();
}
|
|
|
Submitted by Rahimv on Wed, 08/25/2010 - 13:19
/*
* Create a program which writes different data types to a file using PrintWriter
*/
import java.io.*;
class PrintWriterDemo
{
public static void main(String args[])
{
try
{
FileOutputStream fw = new FileOutputStream("C:/IO_demo.txt");
PrintWriter pw = new PrintWriter(fw);
pw.println(true); // boolean data type
|
|
|
Submitted by Rahimv on Wed, 08/25/2010 - 13:12
/*
* Create a program which reads line from console and prints number of characters. Program
* should read the line from keyboard. Use BufferedReader for reading the line from console.
*/
import java.io.*;
class ReadFromKeyboard
{
public static void main(String args[])
{
try
{
DataInputStream din = new DataInputStream(System.in);
|
|
|
Submitted by Rahimv on Wed, 08/25/2010 - 13:03
/*
Create a program which reads file using readLine method of BufferedReader class. File name
should be supplied using command line argument.
*/
import java.io.*;
class BufferedReaderDemo
{
public static void main(String args[])
{
try
{
FileReader fr = new FileReader(args[0]);
BufferedReader br = new BufferedReader(fr);
String line;
|
|