Skip to main content

Posts:5 Registered: 3/24/10 Moving a file from 1 directory to another

1 reply [Last post]
rikki123s
Offline
Joined: 2010-03-27

Hey everyone.

Ok, so here is the crack.

I am trying to copy a file from one directory within my phone to another using my own j2me program. So far I have managed to get the program to delete and create files using specified file names, but as for actually writing the data to these files, I haven't been so lucky (files are created and deleted, but as for the content, it is not being copied over).

The section of my code that write this method is displayed as follows consider variables outputFile & inputFile to be pre-determines Strings containing the input and output locations of the file (for example, String inputFile = "file:///e:/Images/image.jpg"; String outputFile = "file:///e:/temp/De001.jpg";):

FileConnection fconnOut = (FileConnection)Connector.open(outputFile, Connector.READ_WRITE);
if (!fconnOut.exists()) {
fconnOut.create();
FileConnection fconnIn = (FileConnection)Connector.open(inputFile, Connector.READ_WRITE);

InputStream in = fconnIn.OpenDataInputStream();
OutputStream out = fconnOut.OpenDataOutputStream();

byte[] inBytes = new byte[1024];
int byteNumber;

while ((byteNumber = in.read(inBytes)) > 0) {
out.write(inBytes, 0, byteNumber);
}

fconnIn.delete();
fconnOut.close();
in.close();
out.close();
}

gathering from what I know about j2me, this should work, however it does not. can anyone help me?

thanks in advance, and probably many more thanks later for all your help

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
jaywayjohan
Offline
Joined: 2008-06-18

Try to add a call to flush() in the while loop.