is it possible read from a recordstore and print to a text file?
hi guys
i have a question here
is it possible to read from the data that is already stored in the recordstore and after that , print it to a text File(the text file is not created yet).i have try file connection and it doesnt work the way i wanted it to work....as it creates the files before i pass the data to it.
any help is appreciated .:)
# 4
this is my code . i run in my ktoolbar, i have change the earlier code due to that error
i'm quite new to j2me so pls forgive me if it is a simple error
sorry i dont have that code.but this is the current error i have face and unable to solve it.
error i encounter :
C:\WTK22\apps\TCPClient\src\TCPClient.java:64: cannot find symbol
symbol : variable Connector
location: class TCPClient
FileConnection fileConnection = (FileConnection) Connector.open(filename, Connector.READ_WRITE);
^
C:\WTK22\apps\TCPClient\src\TCPClient.java:64: cannot find symbol
symbol : variable Connector
location: class TCPClient
FileConnection fileConnection = (FileConnection) Connector.open(filename, Connector.READ_WRITE);
^
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import java.io.*;
import javax.microedition.io.file.*;
public class TCPClient extends MIDlet implements CommandListener ,ItemCommandListener {
private Display display;
private Form form;
private Command exit, scgIndex,clear;
private TextField txtField;
private ChoiceGroup sImage;
private int sIndex;
private String strTxtField;
private Image image;
public TCPClient(){
display=Display.getDisplay(this);
form=new Form("TCPClient");
txtField=new TextField("type what u want to send","that's all folks",30,TextField.ANY);
sImage= new ChoiceGroup("pls select", Choice.EXCLUSIVE);
sImage.append("no image",null); //=0
sImage.append("image",null); //=1
exit=new Command("Exit",Command.EXIT,1); //1= highest priority,
scgIndex=new Command("select", Command.ITEM,2);//2 =second highest
clear=new Command("clear",Command.ITEM,2);
form.append(txtField);
form.append(sImage);
form.addCommand(clear);
form.addCommand(exit);
form.setCommandListener(this);
try{
Image image= Image.createImage("/send.jpg");
ImageItem imageItem=new ImageItem(null,image,Item.LAYOUT_CENTER ,null,Item.BUTTON);
imageItem.setDefaultCommand( new Command("Set", Command.ITEM, 1));
imageItem.setItemCommandListener(this);
form.append(imageItem);
}//end of try
catch(IOException e){System.out.println("button error");}
}// end of constructor
public void startApp(){
System.out.println("midlet started");
ItemStateListener listener = new MyStateListener();
form.setItemStateListener(listener);// register for events
display.setCurrent(form);
String filename = "file:///root1/hello.txt";
byte[] data = "hello world".getBytes();
FileConnection fileConnection = (FileConnection) Connector.open(filename, Connector.READ_WRITE);
if ( ! fileConnection.exists()) {
fileConnection.create();
}
OutputStream outputStream = fileConnection.openOutputStream();
outputStream.write(data);
outputStream.close();
}
public void pauseApp(){}
public void destroyApp(boolean unconditional){}
public void commandAction(Command c, Displayable s){
if(c==exit){
destroyApp(false);
notifyDestroyed();
}
else if (c==clear){
strTxtField=txtField.getString();// store "that all folks"
System.out.println(strTxtField);
}//end of c0mmand=clear
} // end of commandAction
public void commandAction(Command c, Item item){
}//emd of commandAction method
private class MyStateListener implements ItemStateListener
{
boolean pictureIsShown=false; //Remember the state
int pictureIndex; //Remember the index
public void itemStateChanged(Item item)
{
if(item==sImage){
sIndex=sImage.getSelectedIndex();
switch(sIndex){
case 0:System.out.println(sIndex);
if (!pictureIsShown){
form.delete(pictureIndex);}
break; // end of case0
case 1:System.out.println(sIndex);
if (!pictureIsShown){
try{
ImageItem logo= new ImageItem("",Image.createImage ("/misa.jpg"),ImageItem.LAYOUT_CENTER,"");
pictureIndex=form.append(logo);
System.out.println("success");
}
catch(IOException e)
{System.out.println("error");}}//end of if
break;
default: System.out.println("kiss my ass");
}//end of switch
}//end of if
//do something
}
}
}
thanks in advance