- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在下面的代码语句中:
SmbFileInputStream din==new SmbFileInputStream(src);
我正在尝试创建一个 SmbFileInputStream 对象。如果 SmbFile 'src' 是一个文件,这将工作正常,但如果 'src' 是一个 smb 目录,那么它会抛出异常:
jcifs.smb.SmbException: Access is Denied.
at jcifs.smb.SmbTransport.checkStatus(SmbTransport.java:622)
at jcifs.smb.SmbTransport.send(SmbTransport.java:722)
at jcifs.smb.SmbSession.send(SmbSession.java:262)
at jcifs.smb.SmbTree.send(SmbTree.java:119)
at jcifs.smb.SmbFile.send(SmbFile.java:785)
at jcifs.smb.SmbFile.open0(SmbFile.java:1009)
at jcifs.smb.SmbFile.open(SmbFile.java:1026)
at jcifs.smb.SmbFileInputStream.<init>(SmbFileInputStream.java:73)
at jcifs.smb.SmbFileInputStream.<init>(SmbFileInputStream.java:65)
at testhelp.main(testhelp.java:25)
这段代码有什么问题?或者我哪里出错了?
您好,请检查此代码:
case DOWNLOAD2:
/*This code snippet is used to download a file/folder from smb nETWORK to android sd card.
when I run this code its throwing some exception. It have commented where ever necessary. rest of the code is self
explanatory. So please go through the code and please tell why this exception is thrown.
IF POSSIBLE PLEASE ADD A PROGRESS BAR WHICH SHOULD HELP USER SAYING SOME WORK IS GOING ON.
I have tried including a progress bar, but its not working. I ve read some materials related to this,
but every thing makes use threads. I am not that good at threads. So is it possible to include a progess bar,
without using threads?If possible please help me to do it.
And this code is working file for smb files, I dont know why its throwing exception in case of directories.
Please see why this is throwing exception..
So please see that the modified code contains:
a)no exceptions
b)a progress bar(more specifically a horizontal bar)*/
/*exception thrown:
jcifs.smb.SmbException: Access is Denied.
at jcifs.smb.SmbTransport.checkStatus(SmbTransport.java:622)
at jcifs.smb.SmbTransport.send(SmbTransport.java:722)
at jcifs.smb.SmbSession.send(SmbSession.java:262)
at jcifs.smb.SmbTree.send(SmbTree.java:119)
at jcifs.smb.SmbFile.send(SmbFile.java:785)
at jcifs.smb.SmbFile.open0(SmbFile.java:1009)
at jcifs.smb.SmbFile.open(SmbFile.java:1026)
at jcifs.smb.SmbFileInputStream.<init>(SmbFileInputStream.java:73)
at jcifs.smb.SmbFileInputStream.<init>(SmbFileInputStream.java:65)
at testhelp.main(testhelp.java:25)*/
StatFs statFs = new StatFs(Environment.getExternalStorageDirectory().getAbsolutePath());
//if sd card is mounted then only this operation occur:
if(Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED))
{
//object.getCount() gets the number of objects in list view
for(int i=0;i<object.getCount();i++)
{
//for each object in list view, if it is checked:
if(object.getter(i)==true)
{
SmbFileInputStream din=null;
FileOutputStream dout=null;
try
{
//I have used a hash table, which maps list view name with smb object
SmbFile src=map.get(object.getItem(i));
long blockSize = statFs.getBlockSize();
long freeSize = statFs.getFreeBlocks()*blockSize;
long diff=freeSize-src.length();
boolean can=false;
if(!(diff<0))
{
can=true;
}
if(!src.isHidden() && can)
{
try
{
if(src.isFile())
{
din=new SmbFileInputStream(src);
dout=new FileOutputStream(Environment.getExternalStorageDirectory()+"/"+src.getName());
}
else
{
din=new SmbFileInputStream(src);
File outputFile = new File(Environment.getExternalStorageDirectory()+"/"+src.getName()); // ADDED
outputFile.mkdirs(); // ADDED
dout=new FileOutputStream(outputFile); // CHANGED
}
int c;
while((c=din.read())!=-1)
{
dout.write(c);
}
}
finally
{
if (din != null)
{
din.close();
}
if (dout != null)
{
dout.close();
}
}
}
else
{
Toast.makeText(this,src.getName()+" cannot be downloaded",Toast.LENGTH_LONG).show();
}
}
catch(IOException e)
{
Toast.makeText(this,"DOWNLOAD FAILED--IO EXCEPTION\n"+e,Toast.LENGTH_LONG).show();
}
}
}
}
else
{
Toast.makeText(this,"DOWNLOAD FAILED--NO SD CARD FOUND",Toast.LENGTH_LONG).show();
}
return true;
最佳答案
您不能为目录创建SmbFileInputStream
,因为您不能直接读/写目录对象。目录没有任何内容,至少与文件有内容的方式不同。
如果您尝试读取目录的内容,您可能应该改用 SmbFile
(例如,使用 listFiles()
方法)。 SmbFileInputStream
对象仅用于从文件中读取信息。
要将文件写入目录,请执行此操作...
File file = new File("/mnt/sdcard/filename.txt");
file.mkdirs(); // this creates all the directories that are missing
FileOutputStream os = new FileOutputStream (file);
// now write the file data
os.write(...);
在您的代码中,更改以下几行...
try
{
din=new SmbFileInputStream(src);
dout=new FileOutputStream(Environment.getExternalStorageDirectory()+"/"+src.getName());
int c;
while((c=din.read())!=-1)
为此...
try
{
din=new SmbFileInputStream(src);
File outputFile = new File(Environment.getExternalStorageDirectory()+"/"+src.getName()); // ADDED
outputFile.mkdirs(); // ADDED
dout=new FileOutputStream(outputFile); // CHANGED
int c;
while((c=din.read())!=-1)
同时更改以下...
if(src.isFile()){
din=new SmbFileInputStream(src);
//dout=new FileOutputStream(Environment.getExternalStorageDirectory()+"/"+src.getName());// REMOVE THIS LINE
File outputFile = new File(Environment.getExternalStorageDirectory()+"/"+src.getName()); // ADDED
outputFile.mkdirs(); // ADDED
dout=new FileOutputStream(outputFile); // ADDED
}
else {
//din=new SmbFileInputStream(src); // REMOVE THIS LINE
File outputFile = new File(Environment.getExternalStorageDirectory()+"/"+src.getName());
outputFile.mkdirs();
//dout=new FileOutputStream(outputFile); // REMOVE THIS LINE
}
关于java - smb 目录的 jcifs.smb.SmbException : Access is Denied. 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10433119/
我们使用 JCIFS (1.3.17) 从 Windows 2003 文件服务器加载图像文件。不幸的是,加载到 16384 个文件后停止工作,并且在尝试访问更多文件时出现以下异常: jcifs.smb
我正在尝试通过 JCIFS 访问公司网络中的共享文件夹。但是当我尝试列出共享文件夹下的文件时,它会抛出 SmbException,如下所示, jcifs.smb.SmbException: 0xC00
我正在将文件从 Android 设备写入 Windows 文件夹 所有内容均完好无损但我无法写新行 NtlmPasswordAuthentication auth = new NtlmPass
我正在使用 jCIFS (SMB) 从 java 桌面应用程序访问网络驱动器。我注意到第一次访问大约需要 6 秒,但之后几乎没有延迟。 但是,当我连接到新线程上的网络路径时,首次访问时的 6 秒延迟再
如何使用 JCIFS 获取文件夹中最后修改的文件的名称?我不想使用循环。我找到了方法 lastModified() 和 getDate(),但它们给了我一组随机数(它们看起来根本不像“日期”)。 最佳
我需要连接到 UNC“目录”并在该目录中创建一个文件。我在 stackoverflow 上找到了这个条目:access to file using Java with Samba JCIFS .一件好
我正在使用 JCIFS 写入 Windows 共享。这一直很好用。突然间它停止工作,我现在收到 jcifs.smb.SmbAuthException:访问被拒绝。异常(exception)。我知道我的
我正在尝试列出 samba 中的所有文件和目录。 所以我创建了一个 SmbFile : SmbFile smb = new SmbFile("smb:\\\\10.0.4.3\\sharedFiles
我有一个读取数据库的进程来收集大约 200,000 个文件(并且还在增长)的服务器和路径信息。我使用 JCIFS 库来检查文件是否存在于指定位置,使用以下内容一次一个: SmbFile file =
我正在尝试使用外部 jcifs library 从网络共享读取文件。我能找到的大多数用于读取文件的示例代码都非常复杂,甚至可能不必要。我找到了一种写入文件的简单方法,如下所示。有没有办法使用类似的语法
我已将responseTimeout和soTimeout设置为15000ms,但我仍然得到90000ms 后超时。 我在 v1.3.18 和 v1.3.17 上对此进行了测试。 当我不注册 jcifs
这是我上个月发布的一个问题的重复,但我仍然没有解决。我尝试在 Android 应用程序中使用 jcifs 与我的 Windows 计算机通信,但该应用程序在尝试连接到网络时中止且没有错误消息。我没有看
我使用 jcifs-1.3.17 库来检查共享文件夹上的一些文件。一周前,我发现我的代码无法正常工作。我遇到 500 服务器错误,如下所示: (类:jcifs/smb/NtlmPasswordAuth
我正在将远程文件从 Windows 共享文件夹复制到 Linux 机器。复制需要很长时间。在 320 MB 中,10 小时内仅复制了 200 Kb。 这是我的代码片段: try { Strin
我正在使用 Java CIFS Client Library但面临的问题是 copyTo 函数不起作用。我有一个包含文件的文件夹。我想将这些文件读取到其他网络路径。 String path1 = "
我正在开发一个 Android 应用程序,它可以在 Windows PC 上写入和读取文件 (*.txt)。该应用程序连接到 WiFi 网络并使用 SMB。当网络有互联网连接时,该应用程序运行良好。当
我在 Android SDK 中使用 Smb。 我有下一个代码: public AuthListFiles() throws Exception { 1 SmbFile file = n
我正在使用以下 JCIFS 代码将文件从本地磁盘复制到共享驱动器 public boolean copyFiles(String srcFilePath, String destinationFile
我只是在测试 JCIFS用于访问 Windows 共享。它非常慢,以至于完全无法使用。 import jcifs.smb.*; class First { public static void
是否有 JCIFS NTLM 库的替代品? 最佳答案 华夫饼 - https://github.com/dblock/waffle 具有过滤器、身份 validator 、支持 spring-secu
我是一名优秀的程序员,十分优秀!