package com.badlogic.gdx.backends.android;\r
\r
import java.io.File;\r
-import java.io.FileInputStream;\r
-import java.io.FileNotFoundException;\r
-import java.io.FileOutputStream;\r
import java.io.IOException;\r
import java.io.InputStream;\r
-import java.io.OutputStream;\r
\r
import android.content.res.AssetManager;\r
\r
-import com.badlogic.gdx.Gdx;\r
import com.badlogic.gdx.Files.FileType;\r
+import com.badlogic.gdx.Gdx;\r
import com.badlogic.gdx.files.FileHandle;\r
import com.badlogic.gdx.utils.GdxRuntimeException;\r
\r
public FileHandle parent () {\r
File parent = file.getParentFile();\r
if (parent == null) {\r
- if (type == FileType.Classpath || type == FileType.Absolute)\r
+ switch (type) {\r
+ case Classpath:\r
+ case Absolute:\r
parent = new File("/");\r
- else\r
- parent = new File(".");\r
+ break;\r
+ case Internal:\r
+ parent = new File("");\r
+ break;\r
+ case External:\r
+ parent = new File(Gdx.files.getExternalStoragePath());\r
+ break;\r
+ }\r
}\r
return new AndroidFileHandle(assets, parent, type);\r
}\r
import java.io.File;\r
\r
import com.badlogic.gdx.Files.FileType;\r
+import com.badlogic.gdx.Gdx;\r
import com.badlogic.gdx.files.FileHandle;\r
\r
/**\r
public FileHandle parent () {\r
File parent = file.getParentFile();\r
if (parent == null) {\r
- if (type == FileType.Classpath || type == FileType.Absolute)\r
+ switch (type) {\r
+ case Classpath:\r
+ case Absolute:\r
parent = new File("/");\r
- else\r
- parent = new File(".");\r
+ break;\r
+ case Internal:\r
+ parent = new File("");\r
+ break;\r
+ case External:\r
+ parent = new File(Gdx.files.getExternalStoragePath());\r
+ break;\r
+ }\r
}\r
return new JoglFileHandle(parent, type);\r
}\r
import java.io.File;\r
\r
import com.badlogic.gdx.Files.FileType;\r
+import com.badlogic.gdx.Gdx;\r
import com.badlogic.gdx.files.FileHandle;\r
\r
/**\r
public FileHandle parent () {\r
File parent = file.getParentFile();\r
if (parent == null) {\r
- if (type == FileType.Classpath || type == FileType.Absolute)\r
+ switch (type) {\r
+ case Classpath:\r
+ case Absolute:\r
parent = new File("/");\r
- else\r
- parent = new File(".");\r
+ break;\r
+ case Internal:\r
+ parent = new File("");\r
+ break;\r
+ case External:\r
+ parent = new File(Gdx.files.getExternalStoragePath());\r
+ break;\r
+ }\r
}\r
return new LwjglFileHandle(parent, type);\r
}\r
Classpath,\r
\r
/**\r
- * Path relative to the asset directory on Android and to the application's root directory on the desktop. Internal files\r
- * are always readonly.\r
+ * Path relative to the asset directory on Android and to the application's root directory on the desktop. On the desktop,\r
+ * if the file is not, the classpath is then checked. This enables files to be found when using JWS or applets. Internal\r
+ * files are always readonly.\r
*/\r
Internal,\r
\r
this.type = type;\r
\r
switch (type) {\r
+ case Internal:\r
+ file = new File(fileName);\r
+ if (file.exists()) break;\r
+ // Fall through.\r
case Classpath:\r
if (FileHandle.class.getResourceAsStream("/" + fileName) == null)\r
throw new GdxRuntimeException("File not found: " + fileName + " (" + type + ")");\r
file = new File("/" + fileName);\r
break;\r
- case Internal:\r
- file = new File(fileName);\r
- if (!file.exists()) throw new GdxRuntimeException("File not found: " + file + " (" + type + ")");\r
- break;\r
case External:\r
file = new File(Gdx.files.getExternalStoragePath() + fileName);\r
break;\r
* {@link FileType#Internal} and the file doesn't exist, or if it could not be read.\r
*/\r
public InputStream read () {\r
- if (type == FileType.Classpath) {\r
+ if (type == FileType.Classpath || (type == FileType.Internal && !file.exists())) {\r
InputStream input = FileHandle.class.getResourceAsStream(file.getPath().replace('\\', '/'));\r
if (input == null) throw new GdxRuntimeException("File not found: " + file + " (" + type + ")");\r
return input;\r
}\r
- if (type == FileType.Internal && !file.exists())\r
- throw new GdxRuntimeException("File not found: " + file + " (" + type + ")");\r
try {\r
return new FileInputStream(file);\r
} catch (FileNotFoundException ex) {\r
* Returns the length in bytes of this file, or 0 if this file is a directory or does not exist.\r
*/\r
public long length () {\r
- if (type == FileType.Classpath || type == FileType.Internal) {\r
+ if (type == FileType.Classpath || (type == FileType.Internal && !file.exists())) {\r
try {\r
InputStream input = read();\r
long length = input.available();\r
\r
private void testWriteRead (String path, FileType type) {\r
FileHandle handle = Gdx.files.getFileHandle(path, type);\r
+ handle.delete();\r
if (handle.exists()) fail();\r
if (handle.isDirectory()) fail();\r
if (handle.delete()) fail();\r