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 .:)

[369 byte] By [kenneth-rocka] at [2007-11-26 23:41:27]
# 1
If your device doesen't support File Connection API then better to read the data from the recordstore and pass it OTA via http to a backend server where you could write te information to a flat file.~Mohan
itsmohana at 2007-7-11 15:09:06 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 2

i have try using a fileconnection API

however when i run the program it will hang due to a deadlock.( i place the coding in the commandAction method)

however if i shift the coding to some where else ,it will show the create-read file message before running the program, which i dont want

kenneth-rocka at 2007-7-11 15:09:06 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 3
Can we see some code here. . .~Mohan
itsmohana at 2007-7-11 15:09:06 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 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

kenneth-rocka at 2007-7-11 15:09:06 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 5
i have solved the current problem but encounter new errorc my latest post
kenneth-rocka at 2007-7-11 15:09:06 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 6

Firstly there is nothing like simple or complex errors. Even simple errors sometimes seems to be more complex.

Enable FileConnection i.e. JSR 75 in toolkit before you compile your code. since, compiler is unable to find FileConnection class in the classpath.

We all have gone thro' these phases before. Kindly do not ask for forgiveness in the forum.

~Mohan

itsmohana at 2007-7-11 15:09:06 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 7
hmmmm.i can save the value of the textfield but is it possible to read from the recordstore and print it to the text file?
kenneth-rocka at 2007-7-11 15:09:06 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 8
only find this on printing http://www.hcilab.org/documents/tutorials/Brother/index.html http://java.sun.com/j2se/1.4.2/docs/guide/jps/index.htmlso to answer to your question it is: YES but it will be difficult !!!good luck
suparenoa at 2007-7-11 15:09:06 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 9
hmmm i c. is there any simpler way other than that.i'm quite new to j2me.apologies
kenneth-rocka at 2007-7-11 15:09:06 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 10
JAVA programming is not a simple stuff to do as an hobby ...if you are so new to J2ME, read tutorials, try easy stuff will you run a marathon without training?will you drive a car without learning?same in java. read, learn and after do hard stuff!
suparenoa at 2007-7-11 15:09:06 > top of Java-index,Java Mobility Forums,Java ME Technologies...