Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Java Micro Edition
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Tim Cooke
Campbell Ritchie
Ron McLeod
Junilu Lacar
Liutauras Vilda
Sheriffs:
Paul Clapham
Jeanne Boyarsky
Henry Wong
Saloon Keepers:
Tim Moores
Tim Holloway
Stephan van Hulst
Piet Souris
Carey Brown
Bartenders:
Jesse Duncan
Frits Walraven
Mikalai Zaikin
Forum:
Java Micro Edition
Copy/Move files
Will Richardson
Greenhorn
Posts: 16
I like...
posted 11 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Ok.. Another mobile
Java
question.
I want to know how to copy a file from one place to another on my phone with my java app (It will be used to randomly change the background..)
I have a snippet of code which creates a file on my "E:" drive
public void createFile() { try { FileConnection filecon = (FileConnection) Connector.openInputStream("file:///E:/mynewfile.txt"); // Always check whether the file or directory exists. // Create the file if it doesn't exist. if(!filecon.exists()) { filecon.create(); } filecon.close(); } catch(IOException ioe) { ioe.printStackTrace(); } }
If this met an inputstream of some kind.. I think it would function..
Churs,
Will.
Gopinath Karyadath
Ranch Hand
Posts: 87
posted 11 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
public boolean writeFile(String s) { byte[] data = s.getBytes(); file = System.getProperty("fileconn.dir.photos") + "myfile.txt"; //;append=true"; FileConnection c = null; java.io.OutputStream os = null; try { c = (FileConnection) Connector.open(file, Connector.READ_WRITE); if (c.exists()) { c.delete(); } c.create(); os = c.openOutputStream(); os.write(data); os.flush(); os.close(); c.close(); data = null; s = null; return true; } catch (Exception e) { data = null; s = null; System.gc(); return false; } finally { try { if (os != null) { os.close(); } if (c != null) { c.close(); } } catch (Exception ex) { ex.printStackTrace(); } data = null; s = null; } }
Will Richardson
Greenhorn
Posts: 16
I like...
posted 11 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
I am afraid to say that your code does not function; It creates an unreadable file at the destination.
I am willing to say my code is incorrect, so it is included here: (there are 104 image files in the folder "Wallpapers")
protected void startApp() throws MIDletStateChangeException { // TODO Auto-generated method stub Random randomGenerator = new Random(); int randomInt = randomGenerator.nextInt(104); String str=Integer.toString(randomInt); String dir = "file:///E:/Photos/Wallpapers/"+str+".jpg"; writeFile(dir); notifyDestroyed(); return; } public boolean writeFile(String s) { byte[] data = s.getBytes(); String file = "file:///C:/Settings/UserWP_1.jpg";// System.getProperty("fileconn.dir.photos") // + "myfile.txt"; // // ;append=true"; FileConnection c = null; java.io.OutputStream os = null; try { c = (FileConnection) Connector.open(file, Connector.READ_WRITE); if (c.exists()) { c.delete(); } c.create(); os = c.openOutputStream(); os.write(data); os.flush(); os.close(); c.close(); data = null; s = null; return true; } catch (Exception e) { data = null; s = null; System.gc(); return false; } finally { try { if (os != null) { os.close(); } if (c != null) { c.close(); } } catch (Exception ex) { ex.printStackTrace(); } data = null; s = null; } }
Churs,
Will.
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Application not authorized to access the restricted api
Regarding FileConnection ...
Problems with Player -- no sounds.
kXML users ...
Basic question about file Creation in J2ME
More...