CrazyEngineers
  • why this code does not execute

    Updated: Oct 26, 2024
    Views: 1.0K
    //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();
    }
    }
    0
    Replies
Howdy guest!
Dear guest, you must be logged-in to participate on CrazyEngineers. We would love to have you as a member of our community. Consider creating an account or login.
Replies
  • Manish Goyal

    MemberOct 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
    Are you sure? This action cannot be undone.
    Cancel
  • anandkumarjha

    MemberOct 2, 2010

    Hello CEans
    can anyone explain me the use of volatile modifier in java programming???
    Are you sure? This action cannot be undone.
    Cancel
  • vinci

    MemberNov 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>
    Are you sure? This action cannot be undone.
    Cancel
  • The_Small_k

    MemberNov 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();
        }
    }
    
    Are you sure? This action cannot be undone.
    Cancel
Home Channels Search Login Register