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