Join
Blogs
Questions
Videos
Tags
Members
Search
 
 
Create your own blog, earn points and get popular!

Rahimv's blog

Rahimv's picture

Write a program that prints last n lines of a file like Unix tail command

1
Your rating: None Average: 1 (1 vote)
  1. /*
  2.  * Write a program that prints last n lines of a file like Unix tail command. Program
  3.  * should take file name and number of lines to print from command line arguments. Assume
  4.  * that each line is of 100 bytes approx.
  5.  */
  6.  
  7. import java.io.*;
  8.  
  9. class TailCommand
  10. {
  11.  public static void main(String args[])
  12.  {
  13.   try
  14.   {
Rahimv's picture

Write a program that counts words and numbers in the file using StreamTokenizer

0
Your rating: None
  1. /*
  2.  * Write a program which counts words and numbers in the file using StreamTokenizer. Program
  3.  * should take file name from command line argument.
  4.  */
  5.  
  6. import java.io.*;
  7.  
  8. class StreamTokenizerDemo
  9. {
  10.  public static void main(String args[])
  11.  {
  12.   int numberOfWords = 0;
  13.   int numberOfNumbers = 0;
  14.  
  15.   try{
  16.    
  17.    // create a stream tokenizer
Rahimv's picture

Write a program which counts number of vowels in a file

1.666665
Your rating: None Average: 1.7 (3 votes)
  1. /*
  2.  * Write a program which counts number of vowels in a file. Program should take
  3.  * file name from command line argument.
  4.  */
  5.  
  6. import java.io.*;
  7.  
  8. class CountVowels
  9. {
  10.  public static void main(String args[])
  11.  {
  12.   int i;
  13.   int count = 0;
  14.   try
  15.   {
  16.    FileReader fr = new FileReader(args[0]);
  17.    while((i=fr.read()) != -1)
  18.    {
  19.     switch((char)i)
  20.     {
Rahimv's picture

Create a program which prints number of lines in the file

0
Your rating: None
  1. /*
  2. Create a program which prints number of lines in the file. File name
  3. should be supplied using command line argument.
  4. */
  5.  
  6. import java.io.*;
  7. class CountNumberOfLinesFile
  8. {
  9.  public static void main(String args[])
  10.  {
  11.   try
  12.   {
  13.    FileReader fr = new FileReader(args[0]);
  14.    BufferedReader br = new BufferedReader(fr);
  15.    String line;
  16.    int count = 0;
  17.    
Rahimv's picture

Write a program which copies file and chages all characters to upper case characters

1
Your rating: None Average: 1 (2 votes)
  1. /*
  2.  * Write a program which copies file and chages all characters
  3.  * to upper case characters. Program should take source and destination file names
  4.  * from command line arguments.
  5.  */
  6.  
  7. import java.io.*;
  8.  
  9. class CopyConvertCase
  10. {
  11.  public static void main(String args[])
  12.  {
  13.   int i;
  14.   try
  15.   {
  16.    FileReader fr = new FileReader(args[0]);
Rahimv's picture

Create a program which writes binary data to a file using BufferedOutputStream

0
Your rating: None
  1. /*
  2.  * Create a program which writes binary data to a file using BufferedOutputStream. Program should take
  3.  * file name from command line argument.
  4.  */
  5.  
  6. import java.io.*;
  7.  
  8. class BufferedOutputStreamDemo
  9. {
  10.  public static void main(String args[])
  11.  {
  12.   try
  13.   {
  14.    FileOutputStream fos = new FileOutputStream(args[0]);
  15.    BufferedOutputStream bos = new BufferedOutputStream(fos);
Rahimv's picture

Create a program which reads binary file using FileInputStream

0
Your rating: None
  1. /*
  2.  * Create a program which reads binary file using FileInputStream. Get name of the
  3.  * file from command line argument.
  4.  */
  5.  
  6. class FileInputStreamDemo
  7. {
  8.  public static void main(String args[])
  9.  {
  10.   try
  11.   {
  12.    FileInputStream fis = new FileInputStream(args[0]);
  13.    int i;
  14.    
  15.    while((i = fis.read())!= -1){
  16.     System.out.print(i);
  17.    }
  18.    
  19.    fis.close();
  20.   }
Rahimv's picture

Create a program which writes different data types to a file using PrintWriter

0
Your rating: None
  1. /*
  2.  * Create a program which writes different data types to a file using PrintWriter
  3.  */
  4.  
  5. import java.io.*;
  6.  
  7. class PrintWriterDemo
  8. {
  9.  public static void main(String args[])
  10.  {
  11.   try
  12.   {
  13.    FileOutputStream fw = new FileOutputStream("C:/IO_demo.txt");
  14.    PrintWriter pw = new PrintWriter(fw);
  15.    
  16.    pw.println(true);  // boolean data type
Rahimv's picture

Create a program which reads a line from console and prints number of characters

3
Your rating: None Average: 3 (1 vote)
  1. /*
  2.  * Create a program which reads line from console and prints number of characters. Program
  3.  * should read the line from keyboard. Use BufferedReader for reading the line from console.
  4.  */
  5.  
  6. import java.io.*;
  7.  
  8. class ReadFromKeyboard
  9. {
  10.  public static void main(String args[])
  11.  {
  12.   try
  13.   {
  14.    DataInputStream din = new DataInputStream(System.in);
Rahimv's picture

Create a program which reads file using readLine method of BufferedReader class

0
Your rating: None
  1. /*
  2. Create a program which reads file using readLine method of BufferedReader class. File name
  3. should be supplied using command line argument.
  4. */
  5.  
  6. import java.io.*;
  7. class BufferedReaderDemo
  8. {
  9.  public static void main(String args[])
  10.  {
  11.   try
  12.   {
  13.    FileReader fr = new FileReader(args[0]);
  14.    BufferedReader br = new BufferedReader(fr);
  15.    String line;
  16.    
Syndicate content