gonzaman666
Ville : sousse
Membre depuis : 22 oct. 2006
Messages : 5
|
22 févr. 2007 à 13:57
voila le code et ça marche , j'ai trouver la solution:
*****************************************************************
package testrms;
import java.io.*;
import javax.microedition.io.*;
import javax.microedition.io.file.*;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
public class base extends MIDlet {
public base() {
}
public void startApp() {
new Thread(new Runnable(){
public void run(){
showFile("root1//zz.txt");
}
}).start();
}
public void pauseApp() {
}
public void destroyApp(boolean cond) {
notifyDestroyed();
}
void showFile(String fileName) {
try {
FileConnection fc =
(FileConnection)Connector.open("file://localhost/"+ fileName);
if (!fc.exists()) {
throw new IOException("File does not exists");
}
InputStream fis = fc.openInputStream();
byte[] b = new byte[1024];
int length = fis.read(b, 0, 1024);
fis.close();
fc.close();
TextBox viewer =
new TextBox("View File: " + fileName, null, 1024,
TextField.ANY | TextField.UNEDITABLE);
if (length > 0) {
viewer.setString(new String(b, 0, length));
}
Display.getDisplay(this).setCurrent(viewer);
} catch (Exception e) {
Alert alert =
new Alert("Error!",
"Can not access file " + fileName + " in directory " +
"\nException: " + e.getMessage(), null, AlertType.ERROR);
alert.setTimeout(Alert.FOREVER);
Display.getDisplay(this).setCurrent(alert);
}
}
}
--- gonzaJ2ME
|