mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-01 06:19:57 +01:00
add file open/save functions.
This commit is contained in:
parent
406a6a4a98
commit
531ae8ea1a
1 changed files with 35 additions and 0 deletions
|
@ -7,6 +7,8 @@ import java.lang.Thread;
|
|||
import java.text.MessageFormat;
|
||||
import android.widget.Toast;
|
||||
import android.content.Context;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FileInputStream;
|
||||
|
||||
public class Utils {
|
||||
static final String TAG = "EJAVA";
|
||||
|
@ -35,4 +37,37 @@ public class Utils {
|
|||
Toast.makeText( context, text, Toast.LENGTH_LONG ).show();
|
||||
}
|
||||
|
||||
public static byte[] savedGame( Context context, String path )
|
||||
{
|
||||
byte[] stream = null;
|
||||
try {
|
||||
FileInputStream in = context.openFileInput( path );
|
||||
int len = in.available();
|
||||
Utils.logf( "savedGame: got " + len + " bytes." );
|
||||
stream = new byte[len];
|
||||
in.read( stream, 0, len );
|
||||
in.close();
|
||||
} catch ( java.io.FileNotFoundException fnf ) {
|
||||
Utils.logf( fnf.toString() );
|
||||
stream = null;
|
||||
} catch ( java.io.IOException io ) {
|
||||
Utils.logf( io.toString() );
|
||||
stream = null;
|
||||
}
|
||||
return stream;
|
||||
} // savedGame
|
||||
|
||||
|
||||
public static void saveGame( Context context, byte[] bytes, String path )
|
||||
{
|
||||
try {
|
||||
FileOutputStream out = context.openFileOutput( path, Context.MODE_PRIVATE );
|
||||
out.write( bytes );
|
||||
out.close();
|
||||
} catch ( java.io.IOException ex ) {
|
||||
Utils.logf( "got IOException: " + ex.toString() );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue