Changes

Jump to: navigation, search

Teams Winter 2011/team1/BlackBerry/Use SQLite

1,522 bytes added, 22:47, 11 April 2011
11.5 Copy Database File into SDCard
// here goes the rest of the constructor code
_studentList = new StudentList(db, uri);
</source>
 
Then add the following method (readAndWriteDatabaseFile) to the file that actually reads the database file and puts it into the simulator:
<sourse lang="java">
public void readAndWriteDatabaseFile(FileConnection fileConnection) throws IOException
{
OutputStream outputStream = null;
InputStream inputStream = null;
// Open an input stream to the pre-defined encrypted database bundled
// within this module.
inputStream = getClass().getResourceAsStream("/" + DB_NAME);
// Open an output stream to the newly created file
outputStream = (OutputStream)fileConnection.openOutputStream();
// Read data from the input stream and write the data to the
// output stream.
byte[] data = new byte[256];
int length = 0;
while (-1 != (length = inputStream.read(data)))
{
outputStream.write(data, 0, length);
}
// Close the connections
if(fileConnection != null)
{
fileConnection.close();
}
if(outputStream != null)
{
outputStream.close();
}
if(inputStream != null)
{
inputStream.close();
}
}
</source>
1
edit

Navigation menu