[J2ME]Code for transfering RecordStores from mobile memory to PC Via Cable
Hi,
i m j2me developer, i m developing j2me application in which i want to transfer RecordStores from mobile memory to PC viaCABLE.
I have no idea how to do this task , is there any classes in j2me that provides such facility. is it possible or not ? Please.. so me the way..
Juned Khatri
[321 byte] By [
juneda] at [2007-10-3 4:31:47]

Hi
Yes ..
First ensure that driver for the Data cable is installed.
Get the comm port number .
In windows
control panel->Phone & Modem options ->Modems..
The Comm port no for the data cable is present in Attached To column.
In Linux ..
you can get it by checking the Device options
Next
U need to establish a connection between PC & Handset using the comm port.
Note that The comm port obtained here is the reference commport in the PC..
U can get the comm port number in Handset using the J2ME application itself..
String port;
String ports = System.getProperty("microedition.commports");
int comma = ports.indexOf(',');
if (comma > 0) {
// Parse the first port from the available ports list.
port = ports.substring(0, comma);
} else {
// Only one serial port available.
port =ports;
}
/*Below is a code example showing how you can use serial I/O API to open a connection and read/write
to it. */
//using commconnection since midp2.0
CommConnection commConn =
(CommConnection)Connector.open("comm:COM0;baudrate=115200", Connector.READ_WRITE,
true);
InputStream iStream = commConn.openInputStream();
OutputStream oStream = commConn.openOutputStream();
String sMessage = "send";
oStream.write(sMessage.getBytes());
Thread tRead = new Thread() {
public void run() {
while (true) {
StringBuffer sb = new StringBuffer();
while(true) {
int c = iStream.read();
if(c != '\r') {
sb.append((char)c);
}
else
break;
}
try {
sleep(1000);
}
catch (InterruptedException e) {}
}
}
};
tRead.start();
For some handsets that do not support CommConnection, you can use StreamConnection in place of
CommConnection with the same result:
StreamConnection commConn =
(StreamConnection)Connector.open("comm:COM0";baudrate=115200");
The above code is for J2me application running on Handset ...
In PC you can refer it using the comm port identified from the Control Panel.
Thanks
souvik