1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
   |  
package test;
 
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("rr.txt");
			}
		}).start();
	}
 
	public void pauseApp() {
	}
 
	public void destroyApp(boolean cond) {
		notifyDestroyed();
	}
 
 
	void showFile(String fileName) {
		try {
			FileConnection fc ;
			fc=(FileConnection)Connector.open("file://localhost//"+fileName);
 
			System.out.println("existe ="+fc.exists());
			if (!fc.exists()) {
				throw new IOException("File does not exists");
			}
 
			InputStream fis = fc.openInputStream();
			System.out.println(fc.getURL());
			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);
		}
	}
 
 
} | 
Partager