这两个文件都存在于SD卡上,但无论出于何种原因,exists()都会返回false文件.
//String path = "/mnt/sdcard/Android/data/com.gemoro.toffer/cache/1551619351/0/foto/-921042926.png";
String path = "/mnt/sdcard/Android/data/com.gemoro.toffer/cache/1551619351/0/foto/-1200240592.pdf";
File file2 = new File(path);
if (null != file2)
{
if(file2.exists())
{
LOG.x("file exist");
}
else
{
LOG.x("file does not exist");
}
}
Run Code Online (Sandbox Code Playgroud)
现在,我看看底层是什么,file.exists()实际上做了什么,这就是它的作用:
public boolean exists()
{
return doAccess(F_OK);
}
private boolean doAccess(int mode)
{
try
{
return Libcore.os.access(path, mode);
}
catch (ErrnoException errnoException)
{
return false;
}
}
Run Code Online (Sandbox Code Playgroud)
可能是通过抛出异常并返回false来完成该方法?
如果是这样,
谢谢.
我在android项目中使用asmack最新版本(asmack-android-8-source-0.8.3),我有以下代码:
connection.addPacketListener(new PacketListener()
{
@Override
public void processPacket(Packet p)
{
if(p.getPacketID().equals("v3"))
{
Log.e("TAG", p.toXML());
}
}
}, new IQTypeFilter(IQ.Type.RESULT));
Packet iq = new Packet()
{
@Override
public String toXML()
{
String str = "<iq type='get' id='v3'><getservertime xmlns='urn:xmpp:mrpresence'/></iq>";
Log.e("TAG", str);
return str;
}
};
//sends <iq type='get' id='v3'><getservertime xmlns='urn:xmpp:mrpresence'/></iq>
connection.sendPacket(iq);
Run Code Online (Sandbox Code Playgroud)
在调试器中,响应没问题,这是预期的:
<iq type="result" id="v3" to="minimaal@mrserver/Smack">
<servertime xmlns="urn:xmpp:mrpresence" utc="2013-06-28T11:45:32.380Z" local="2013-06-28T07:45:32.380Z"/>
</iq>
Run Code Online (Sandbox Code Playgroud)
但是包列表器中的p.toXML(),它缺少标签"servertime":
<iq id="v3" to="minimaal@mrserver/Smack" type="result"></iq>
Run Code Online (Sandbox Code Playgroud)
关于我做错的任何建议?
我想使用window.loadUrl("Javascript:window.location.reload(true)"); 重新加载网络视图但无法执行。我可以得到一些建议或替代解决方案吗?我只是想让按钮重新加载重新加载 webview窗口
谢谢,下面的Java:
package com.fortunecaster.android;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
public class FcastActivity extends Activity {
WebView window;
Button reload;
@Override
public void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fcast);
window = (WebView)findViewById(R.id.webView1);
window.getSettings().setJavaScriptEnabled(true);
window.getSettings().setLoadWithOverviewMode(true);
window.getSettings().setUseWideViewPort(true);
window.setWebViewClient(new WebViewClient());
window.setWebChromeClient(new WebChromeClient());
window.getSettings().setAppCacheEnabled(true);
try {
window.loadUrl("http://www.fortunecaster.com/android-td");
} catch (Exception e) {
e.printStackTrace();
//setup button
reload = (Button)findViewById(R.id.button1);
//set onClickListener
reload.setOnClickListener(new View.OnClickListener() {
@Override
public void …Run Code Online (Sandbox Code Playgroud)