www.RoboHobby.com
package com.robohobby.me;
import java.util.*;
import javax.microedition.io.*;
import java.io.*;
import javax.microedition.io.file.*;
@Ads
@author
public class DiscUtils {
String appName = " Disc " ;
CallBacks callBacks = CallBacks.getInstance();
String filePath = " file:///4:/Pictures/DiscData/ " ;
public DiscUtils()
{}
public void writeToDisk( String fileName, byte [] byteData )
{
try
{
FileConnection fconn = (FileConnection)Connector.open(
filePath + fileName
);
if (!fconn.exists())
fconn.create();
java.io.DataOutputStream dOut = fconn.openDataOutputStream();
dOut.write( byteData, 0, byteData.length );
dOut.flush();
dOut.close();
callBacks.robotMIDlet.getInfoStringItem().setText( " writeToDisk() OK " );
fconn.close();
}
catch ( IOException ioe )
{
callBacks.robotMIDlet.getInfoStringItem().setText( " Error ioe= " +ioe );
}
}
public void getRoots()
{
Enumeration drives = FileSystemRegistry.listRoots();
String allRoots = "" ;
int i = 0;
while (drives.hasMoreElements())
{
String root = (String) drives.nextElement();
allRoots += " # " +i+" = " +root+" \r \n " ;
}
callBacks.robotMIDlet.getInfoStringItem().setText( allRoots );
}
public boolean isDiskCommand()
{
boolean retValue = false ;
try
{
FileConnection fconn = (FileConnection)Connector.open(
filePath
);
String listOfFiles = "" ;
Enumeration en = fconn.list();
while ( en.hasMoreElements() )
{
String fileName = (String)en.nextElement();
listOfFiles += fileName + " , " ;
}
if ( listOfFiles.indexOf( " cmd.txt " ) >= 0 )
{
retValue = true ;
}
else
{
retValue = false ;
}
fconn.close();
}
catch ( IOException ioe )
{
}
return retValue;
}
public String readDiskCommand()
{
String retValue = "" ;
try
{
FileConnection fconn = (FileConnection)Connector.open(
this .filePath + " cmd.txt "
);
java.io.DataInputStream dIn = fconn.openDataInputStream();
byte b[] = new byte [20];
if ( dIn.read(b) != -1 )
{
int cmd = b[0];
if ( cmd == 'L' )
{
retValue = " L " ;
}
else if ( cmd == 'R' )
{
retValue = " R " ;
}
else if ( cmd == 'F' )
{
retValue = " F " ;
}
else if ( cmd == 'B' )
{
retValue = " B " ;
}
}
dIn.close();
fconn.close();
}
catch ( IOException ioe )
{
retValue = " Error ioe= " + ioe;
}
catch ( Exception e )
{
retValue = " Error e= " + e;
}
return retValue;
}
public void deleteDiskCommand()
{
boolean isDeleted = false ;
int i = 0;
while ( !isDeleted && i < 20 )
{
try
{
FileConnection fconn = (FileConnection)Connector.open(
this .filePath + " cmd.txt "
);
if ( fconn.exists() )
{
fconn.delete();
isDeleted = true ;
}
else
{
}
try
{
fconn.close();
}
catch ( Exception e )
{
}
}
catch ( IOException ioe )
{
}
i++;
}
}
}
Contact us: