BeginnerProgrammer
جمعه 21 تیر 1392, 14:51 عصر
سلام دوستان ، کسی میدونه چرا این کد درست اجرا نمیشه ؟؟؟؟؟؟؟؟؟/
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package file;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.io.file.*;
import javax.microedition.io.*;
import java.io.*;
/**
* @author ZARA-T
*/
public class ReadMidlet extends MIDlet implements CommandListener {
private Display display;
private Form form;
private Command read, exit;
StringBuffer buff;
public void startApp(){
display = Display.getDisplay(this);
read = new Command("Read", Command.EXIT, 1);
exit = new Command("Exit", Command.EXIT, 1);
form = new Form("Read File");
form.addCommand(exit);
form.addCommand(read);
form.setCommandListener(this);
display.setCurrent(form);
}
public void pauseApp(){}
public void destroyApp(boolean unconditional){
notifyDestroyed();
}
public void commandAction(Command c, Displayable s){
if (c==read) {
try {
String SS;
SS=ReadFile("file:///root1//hello.txt");
TextBox input = new TextBox("Enter Some Text:", "", 5, TextField.ANY);
input.setString(SS);
display.setCurrent(input);
} catch (IOException ex) {
ex.printStackTrace();
}
}
if (c==exit) destroyApp(false);
}
private String ReadFile(String url) throws IOException {
FileConnection fc = (FileConnection) Connector.open(url,Connector.READ);
if(fc.exists())
AlertType.ERROR.playSound(display);
StringBuffer sb = new StringBuffer();
try {
InputStream in = fc.openInputStream();
try {
int i;
while ((i = in.read()) != -1) {
sb.append((char) i);
}
} finally {
in.close();
}
} finally {
fc.close();
}
form.append(sb.toString());
return sb.toString();
}
}
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package file;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.io.file.*;
import javax.microedition.io.*;
import java.io.*;
/**
* @author ZARA-T
*/
public class ReadMidlet extends MIDlet implements CommandListener {
private Display display;
private Form form;
private Command read, exit;
StringBuffer buff;
public void startApp(){
display = Display.getDisplay(this);
read = new Command("Read", Command.EXIT, 1);
exit = new Command("Exit", Command.EXIT, 1);
form = new Form("Read File");
form.addCommand(exit);
form.addCommand(read);
form.setCommandListener(this);
display.setCurrent(form);
}
public void pauseApp(){}
public void destroyApp(boolean unconditional){
notifyDestroyed();
}
public void commandAction(Command c, Displayable s){
if (c==read) {
try {
String SS;
SS=ReadFile("file:///root1//hello.txt");
TextBox input = new TextBox("Enter Some Text:", "", 5, TextField.ANY);
input.setString(SS);
display.setCurrent(input);
} catch (IOException ex) {
ex.printStackTrace();
}
}
if (c==exit) destroyApp(false);
}
private String ReadFile(String url) throws IOException {
FileConnection fc = (FileConnection) Connector.open(url,Connector.READ);
if(fc.exists())
AlertType.ERROR.playSound(display);
StringBuffer sb = new StringBuffer();
try {
InputStream in = fc.openInputStream();
try {
int i;
while ((i = in.read()) != -1) {
sb.append((char) i);
}
} finally {
in.close();
}
} finally {
fc.close();
}
form.append(sb.toString());
return sb.toString();
}
}