Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-23-2008, 08:58 AM
Member
 
Join Date: May 2008
Posts: 2
bbonya is on a distinguished road
How to using read file in FileConnection
Hi all,

please guide how to using FileConnection in j2me??
I try open and read to file. But don't execute.

An exception happened at InputStream in = conn.openInputStream();

Exception messgae is ..

java.io.IOException:

Code:
import java.io.*; import javax.microedition.io.*; import javax.microedition.midlet.*; import javax.microedition.io.file.*; public class FileTest extends MIDlet { protected void destroyApp(boolean arg0) throws MIDletStateChangeException { } protected void pauseApp() { } FileConnection conn = null; String url = "file:///root1/test.txt"; protected void startApp() throws MIDletStateChangeException { try{ System.out.println("Start app"); conn = (FileConnection)Connector.open(url, Connector.READ); } catch(Exception e) { System.out.println("=== Open error ==="); System.out.println(e); } try{ System.out.println(conn); InputStream in = conn.openInputStream(); byte[] b = new byte[1024]; in.read(b,0,10); System.out.println(b); } catch(Exception e) { System.out.println("=== Read error ==="); System.out.println(e); } try{ conn.close(); } catch(Exception e) { System.out.println("=== Close error ==="); System.out.println(e); } } }
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 06-23-2008, 12:18 AM
Nicholas Jordan's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Southwest
Posts: 789
Nicholas Jordan is on a distinguished road
read from LOCAL ? - or testing
Everything I could find worked off the tower. ( iow - seems to assume we are going to the internet ) If it is just a local testing and get-going question, then we might do it like this:
Code:
FileInputStream file = new FileInputStream ("test.txt");// DataInputStream stream = new DataInputStream(file) ;//
Or something similar.

Further questions welcome, it is hard to tell if this is the question it sounds like. Additionally, information may be obtained by trapping the errant code in an exception block, then posting the message it gives.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 06-23-2008, 04:01 AM
Member
 
Join Date: May 2008
Posts: 2
bbonya is on a distinguished road
I find out a solution.

Code:
Enumeration e = FileSystemRegistry.listRoots(); String root = (String)e.nextElement(); String filename = "file:///" + root + filename; FineConnection fc = (FileConnection)Connector.open(filename, Connector.READ); InputStream is = (InputStream)fc.openInputStream();
Thanks for the reply.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to Access Local File Systems from J2ME devices using FileConnection API ndolle CLDC and MIDP 3 06-22-2008 09:25 PM
How to read a text file from a Java Archive File Java Tip Java Tips 0 02-08-2008 11:13 AM
Read file tajinvillage Threads and Synchronization 0 01-29-2008 11:10 AM
read txt file sureshsri1981 JavaServer Pages (JSP) and JSTL 0 08-05-2007 05:49 PM
help to read .pst file through java umadas Advanced Java 0 07-30-2007 04:36 PM


All times are GMT +3. The time now is 09:29 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org