LibGdx从SmbFile加载纹理
我尝试使用位于PC共享文件夹中的图像文件创建Gdx纹理。 该代码在桌面应用程序上运行良好(但不使用SmbFile…),但在android应用程序上崩溃。我获得“无此类文件或目录”错误。 有人知道我们怎么做吗? 谢谢你LibGdx从SmbFile加载纹理,libgdx,smbj,Libgdx,Smbj,我尝试使用位于PC共享文件夹中的图像文件创建Gdx纹理。 该代码在桌面应用程序上运行良好(但不使用SmbFile…),但在android应用程序上崩溃。我获得“无此类文件或目录”错误。 有人知道我们怎么做吗? 谢谢你 public void create () { Gdx.app.setLogLevel(Application.LOG_DEBUG); batch = new SpriteBatch(); SmbFile file
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***
}
是的,尼古拉斯
最后,我首先在本地复制了文件。它可以在android和桌面应用程序上运行。
如果有人感兴趣,可以使用两个函数loadFile和saveFile:
loadFile( "//***path to shared folder***/icon-152.png","icon-152.png");
saveFile("icon-152.png", "//HP2285/***path to shared folder***/icon-152.png");
}
public void loadFile(String smbFilePath, String fileName){
try {
SmbFile file = new SmbFile("smb:"+smbFilePath);
InputStream is = new SmbFileInputStream(file);
FileHandle fhd = Gdx.files.local(fileName);
OutputStream os = fhd.write(false);
byte[] buffer = new byte[1024];
int length;
while ((length = is.read(buffer)) > 0) {
os.write(buffer, 0, length);
}
is.close();
os.close();
}
catch(Exception e){
}
}
public void saveFile(String fileName, String smbFilePath){
try {
SmbFile file = new SmbFile("smb:"+smbFilePath);
OutputStream os = new SmbFileOutputStream(file);
FileHandle fhs = Gdx.files.local(fileName);
InputStream is = fhs.read();
byte[] buffer = new byte[1024];
int length;
while ((length = is.read (buffer)) > 0) {
os.write(buffer, 0, length);
}
is.close();
os.close();
}
catch(Exception e){
}
}
我猜在Android上无法使用
smb://*
路径访问共享文件夹。也许您可以尝试子类化FileHandle
来包装SmbFile
,我假设它可以访问共享文件夹?我没有任何SMB的经验,所以我不能说。