Copy File From one location to another-BlackBerry

This will copy the file located in “path” to “path1“.Replaces with existing file

public boolean CopyFile(String path,String path1)
    {
        boolean str = false;
        try {
            FileConnection fc = (FileConnection)Connector.open(path, Connector.READ);
            FileConnection fc1 = (FileConnection)Connector.open(path1, Connector.READ_WRITE);
            if(!fc1.exists())
            {
            fc1.create();
            }
            fc1.setWritable(true);
            if(!fc.exists())
            {
                System.out.println("Source File doesn't exist!");
            }

            else
            {
                int size = (int)fc.fileSize();
                InputStream is = fc.openInputStream();
                OutputStream os=fc1.openOutputStream();
                byte bytes[] = new byte[size];
                is.read(bytes, 0, size);
                os.write(bytes);
                os.close();
                is.close();
                return true;
            }
        }
        catch (Exception ioe)
        {
            System.out.println("File Sys Error"+ioe.getMessage());
        }
        return str;
    }

No comments:

Post a Comment

Empowering the Future of API Management: Unveiling the Journey of WSO2 API Platform for Kubernetes (APK) Project and the Anticipated Alpha Release

  Introduction In the ever-evolving realm of API management, our journey embarked on the APK project eight months ago, and now, with great a...