我尝试使用位于我 PC 上的共享文件夹中的图像文件创建 Gdx 纹理。该代码在桌面应用程序上运行良好(但在不使用 SmbFile 的情况下也能正常运行......),但在 android 应用程序上崩溃。我收到“没有这样的文件或目录”错误。有人知道我们该怎么做吗?谢谢 !
public void create () {
Gdx.app.setLogLevel(Application.LOG_DEBUG);
batch = new SpriteBatch();
SmbFile file=null;
try {
file = new SmbFile("smb://***path to shared folder***/icon-152.png");
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
FileHandle fileHandle;
fileHandle = new FileHandle(file.getUncPath());
img = new Texture(fileHandle); //***No such file or directory***
//img = new Texture(Gdx.files.external(file.getUncPath())); //***No such file or directory***
}
补充:我尝试将文件复制到资产中,然后将其作为纹理加载。在桌面应用程序上仍然可以正常工作,但在 android 应用程序上仍然出现错误:Java.io.FiliNotFound Exception。
public void create () {
Gdx.app.setLogLevel(Application.LOG_DEBUG);
batch = new SpriteBatch();
SmbFile file=null;
try {
file = new SmbFile("smb://***path to shared folder***/icon-152.png");
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
InputStream is = null;
OutputStream os = null;
try {
is = new FileInputStream(file.getUncPath());
os = new FileOutputStream("test.png");
byte[] buffer = new byte[1024];
int length;
while ((length = is.read(buffer)) > 0) {
os.write(buffer, 0, length);
}
is.close();
os.close();
}
catch(java.io.IOException e){
Gdx.app.log("", e.getMessage()); //***Java.io.FileNotFound Exception***
}
img = new Texture("test.png"); //***No such file or directory***
}