/**
* 获取路径
* 遍历手持机所有跟路径,找出可用空间最大的路径作为返回值,
* 并存入RMS,下次启动程序直接从RMS读取路径
*
* @return
*/
public String getPhonePath() {
String phonePath = "";
try {
RecordStore rootPathRms = RecordStore.openRecordStore("phonePath", true);
int num = rootPathRms.getNumRecords();
if (num > 0) {
byte[] b = rootPathRms.getRecord(1);
phonePath = new String(b, "utf-8");
} else if (phonePath.equals("") || phonePath == null) {
String[] roots = new String[10];
Enumeration e = FileSystemRegistry.listRoots();
int i = 0;
while (e.hasMoreElements()) {
String root = (String) e.nextElement();
roots[i] = root;
i++;
}
long[] rootSizes = new long[i];
for (int j = 0; j < i; j++) {
FileConnection fc;
try {
fc = (FileConnection) Connector.open("file:///"
+ roots[j]);
rootSizes[j] = fc.availableSize();
} catch (IOException e1) {
e1.printStackTrace();
}
}
int index = 0;
long temp = 0;
for (int h = 0; h < rootSizes.length; h++) {
if (rootSizes[h] > temp) {
temp = rootSizes[h];
index = h;
} else
continue;
}
phonePath = roots[index];
rootPathRms.addRecord(phonePath.getBytes(), 0,
phonePath.getBytes().length);
}
} catch (RecordStoreFullException e) {
e.printStackTrace();
} catch (RecordStoreNotFoundException e) {
e.printStackTrace();
} catch (RecordStoreException e) {
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} finally {
try {
rootPathRms.closeRecordStore();
} catch (RecordStoreNotOpenException e) {
e.printStackTrace();
} catch (RecordStoreException e) {
e.printStackTrace();
}
}
return phonePath;
}