why this code does not execute

anandkumarjha

anandkumarjha

@anandkumarjha-jzdDMA Oct 26, 2024
//java CopyFile aage.txt boxdemo.txt
import java.io.*;
class copyfile
{
public static void main(String args[])throws IOException
{
int i;
FileInputStream fin;
FileOutputStream fout;
try
{
fin=new FileInputStream(args[0]);
}
catch(FileNotFoundException e)
{
System.out.println("Input file not found");
return;
}
//open output file
try
{
fout=new FileOutputStream(args[1]);
}
catch(FileNotFoundException e)
{
System.out.println("Erroe opening output file");
return;
}
}
catch(ArrayIndexOutOfBoundsException e)
{
System.out.println("Usage:copyfile from to");
return;
}
//copy file
try
{
do
{
i=fin.read();
if(i!=-1)
fout.write(i);
}
while(i!=-1);
}
catch(IOException e)
{
System.out.println("file error");
}
fis.close();
fout.close();
}
}

Replies

Welcome, guest

Join CrazyEngineers to reply, ask questions, and participate in conversations.

CrazyEngineers powered by Jatra Community Platform

  • Manish Goyal

    Manish Goyal

    @manish-r2Hoep Oct 2, 2010

    There are two errors in your program .In order to remove these errors

    1:-Reconstruct your program with proper indentation.

    2:-There is a very silly error in this program .


    check your program again ,you will find it
  • anandkumarjha

    anandkumarjha

    @anandkumarjha-jzdDMA Oct 2, 2010

    Hello CEans
    can anyone explain me the use of volatile modifier in java programming???
  • vinci

    vinci

    @vinci-e4PtMU Nov 17, 2011

    here:<a href="https://www.javamex.com/tutorials/synchronization_volatile_java_5.shtml" target="_blank" rel="nofollow noopener noreferrer">The volatile keyword in Java 5</a>
  • The_Small_k

    The_Small_k

    @the-small-k Nov 17, 2011

    Try this one
    //java CopyFile aage.txt boxdemo.txt
    import java.io.*;
    class copyfile
    {
        
        public static void main(String args[])throws IOException
        {
            int i;
            FileInputStream fin=null;
            FileOutputStream fout=null;
            try
            {
                fin=new FileInputStream(args[0]);
            }
            catch(FileNotFoundException e)
            {
                System.out.println("Input file not found");
            return;
            }
            //open output file
            try
            {
                fout=new FileOutputStream(args[1]);
            }
            catch(FileNotFoundException e)
            {
                System.out.println("Erroe opening output file");
                return;
            }
            catch(ArrayIndexOutOfBoundsException e)
            {
                System.out.println("Usage:copyfile from to");
                return;
            }
            //copy file
            try
            {
                do
                {
                    i=fin.read();
                    if(i!=-1)
                    fout.write(i);
                }
                while(i!=-1);
            }
            catch(IOException e)
            {
                System.out.println("file error");
            }
            fin.close();
            fout.close();
        }
    }