In such type of cases you can create a Class extending Field
and the following things have to override:
* sublayout()
* paint()
* getPreferredWidth()
* getPreferredHeight()
The below Class demonstrate the above implementation:
|
|
|
|
InputStream inputStream = null; FileConnection fileConnection = (FileConnection) Connector.open( "file:///SDCard/testfile.txt"); if (fileConnection.exists()) { inputStream = fconn.openInputStream(); } ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); byte[] buffer = new byte[BUFFER_SIZE]; while (true) { int bytesRead = inputStream.read( buffer, 0, BUFFER_SIZE ); if (bytesRead == -1) break; byteArrayOutputStream.write( buffer, 0, bytesRead ); } byteArrayOutputStream.flush(); byte[] result = byteArrayOutputStream.toByteArray(); byteArrayOutputStream.close(); String resultString = new String(result); |
FileConnection fc = (FileConnection) Connector.open(System.getProperty("file:///SDCard/"+"fileName.txt"),Connector.READ_WRITE); if(!fc.exists()) { fc.create(); } OutputStream os =fc.openOutputStream(); os.write("Test"); os.close(); fc.close() |
public static void copyFile(String srFile, String dtFile) { try { FileConnection f1; FileConnection f2; f1 = (FileConnection) Connector.open(srFile,Connector.READ_WRITE); f2 = (FileConnection) Connector.open(dtFile,Connector.READ_WRITE); if(!f2.exists()) // if file does not exists , create a new one { f2.create(); } InputStream is = f1.openInputStream(); OutputStream os =f2.openOutputStream(); byte[] buf = new byte[1024]; int len; while ((len = is.read(buf)) > 0) { os.write(buf, 0, len); } is.close(); os.close(); } catch(IOException e) { } } |
|
|
For setting image in the background of the Blackberry screen we need to do the following.
First create a VerticalFieldManager and override the paint method of that manager and then draw Bitmap inside paint() method with the device width and height. Disable vertical scrolling of this manager.
Now create another VerticalFieldManager with vertical scroll enabled. This will be the main manger where screen component have to add. Set the width and height of this manager as Screen width and height by overriding sublayout() method.
|
|
b) C:\Program Files\Java\jre1.6.0_05\bin
c) C:\Program Files\Research In Motion\BlackBerry JDE 4.6.0\bin
6. Restart your PC or simply the logoff will do.
Now we are ready to start HelloWorld in Blackberry :)