
Railwanderer
Ambitioniertes Mitglied
- 11
Hallo zusammen,
ich möchte ein simples Android Game Framework für Java Porten.
wer das ganze Framework sehen möchte bitte in der Signatur auf ForumProjekt klicken und bei Github die 2 Repesitories einsehen.
Wie bewerkstellige ich folgendes unter Java? :
________INTERFACE______
public interface FileIO {
// Load assets from apk package
InputStream readAsset(String fileName) throws IOException;
// Load files from storage (SD)
InputStream readFile(String fileName) throws IOException;
OutputStream writeFile(String fileName) throws IOException;
}
_______ANDROID IMPLEMENTATION_______
public class AndroidFileIO implements FileIO {
Context context;
AssetManager assets;
String externalStoragePath;
// Constructor
public AndroidFileIO(Context context) {
this.context = context;
this.assets = context.getAssets();
this.externalStoragePath = Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator;
}
@override
public InputStream readAsset(String fileName) throws IOException {
return assets.open(fileName);
}
@override
public InputStream readFile(String fileName) throws IOException {
return new FileInputStream(externalStoragePath + fileName);
}
@override
public OutputStream writeFile(String fileName) throws IOException {
return new FileOutputStream(externalStoragePath + fileName);
}
}
ich möchte ein simples Android Game Framework für Java Porten.
wer das ganze Framework sehen möchte bitte in der Signatur auf ForumProjekt klicken und bei Github die 2 Repesitories einsehen.
Wie bewerkstellige ich folgendes unter Java? :
________INTERFACE______
public interface FileIO {
// Load assets from apk package
InputStream readAsset(String fileName) throws IOException;
// Load files from storage (SD)
InputStream readFile(String fileName) throws IOException;
OutputStream writeFile(String fileName) throws IOException;
}
_______ANDROID IMPLEMENTATION_______
public class AndroidFileIO implements FileIO {
Context context;
AssetManager assets;
String externalStoragePath;
// Constructor
public AndroidFileIO(Context context) {
this.context = context;
this.assets = context.getAssets();
this.externalStoragePath = Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator;
}
@override
public InputStream readAsset(String fileName) throws IOException {
return assets.open(fileName);
}
@override
public InputStream readFile(String fileName) throws IOException {
return new FileInputStream(externalStoragePath + fileName);
}
@override
public OutputStream writeFile(String fileName) throws IOException {
return new FileOutputStream(externalStoragePath + fileName);
}
}