Seminar Topics & Project Ideas On Computer Science Electronics Electrical Mechanical Engineering Civil MBA Medicine Nursing Science Physics Mathematics Chemistry ppt pdf doc presentation downloads and Abstract

Full Version: WAP to accept command line arguments and print the values.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
[attachment=71780]



A. Program to demonstrate working of Command-Line Arguments :-
public class Argument
{
public static void main(String[ ] args)
{
System.out.print("Hi, ");
System.out.print(args[0] + " " );
System.out.print(args[1] + " " );
System.out.println(". How are you?");
}
}
OUTPUT :
Hi, Java Programs . How are you?


B. Parsing Numeric Command-Line Arguments :-

public class Argument
{
public static void main(String[ ] args)
{
int number1 = Integer.parseInt(args[0]);
int number2 = Integer.parseInt(args[1]);
int sum = number1 + number2;
System.out.print("The sum of two number is : " + sum);
}
}
OUTPUT :
The sum of two number is : 30 
Question -2
WAP to demonstrate the creation and initialization of Input Streams.

// BufferedCopy.java

import java.io.*;

classBufferedCopy
{
public static void main (String [] args)
{
if (args.length != 2)
{
System.out.println ("usage: java BufferedCopysrcpathdstpath");
return;
}

BufferedInputStreambis = null;
BufferedOutputStreambos = null;

try
{
FileInputStreamfis = new FileInputStream (args [0]);
bis = new BufferedInputStream (fis);

FileOutputStreamfos = new FileOutputStream (args [1]);
bos = new BufferedOutputStream (fos);

int byte_;
while ((byte_ = bis.read ()) != -1)
bos.write (byte_);
System.out.println ("Data Copied");
}
catch (FileNotFoundException e)
{
System.out.println ("File not found");
// Do other stuff related to that exception (if necessary).
}
catch (IOException e)
{
System.out.println ("I/O Problem: " + e.getMessage ());
// Do other stuff related to that exception (if necessary).
}
finally
{
if (bis != null)
try
{
bis.close ();
}
catch (IOException e)
{
}

if (bos != null)
try
{
bos.close ();
}
catch (IOException e)
{
}
}
}
}

Command :-C:\>java BufferedCopy Copy.java Copy.txt
Output :-Data Copied