我在S3上有一个桶,我有大量的文本文件.
我想在文本文件中搜索一些文本.它仅包含原始数据.每个文本文件都有不同的名称.
例如,我有一个桶名称:
ABC/MyFolder文件/ abac.txt
XYX/myfolder1/axc.txt
我想在上面的文本文件中搜索"我是人"这样的文字.
怎么做到这一点?它甚至可能吗?
在Java中读取自定义注释处理器的代码时,我注意到处理器process方法中的这段代码:
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
if (!roundEnv.errorRaised() && !roundEnv.processingOver()) {
processRound(annotations, roundEnv);
}
return false;
}
Run Code Online (Sandbox Code Playgroud)
碰巧我正在使用自定义Annotation处理器,我想在我的注释处理器中使用上面的代码片段.
我用这种方式尝试了上面的代码:
if (!roundEnv.errorRaised() && !roundEnv.processingOver()) {
processRound(annotations, roundEnv);
}
return false;
Run Code Online (Sandbox Code Playgroud)
& 这条路:
if (!roundEnv.errorRaised()) {
processRound(annotations, roundEnv);
}
return false;
Run Code Online (Sandbox Code Playgroud)
但我没有注意到处理器行为的任何变化.我得到了!roundEnv.errorRaised()支票,但我看不出有!roundEnv.processingOver()什么用处.
我想知道roundEnv.processingOver()在处理某一轮时使用它的用例.
我想用Picasso图像缓存下载以下图像下载代码.
DownloadImage downloadImage = new DownloadImage();
downloadImage.execute(advert.getImgUrl());
private class DownloadImage extends AsyncTask<String, Void, Bitmap> {
@Override
protected Bitmap doInBackground(String... arg) {
Bitmap bmp = null;
try {
URL url = new URL(arg[0]);
bmp = BitmapFactory.decodeStream(url.openConnection()
.getInputStream());
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
return null;
}
return bmp;
}
@Override
protected void onPostExecute(Bitmap result) {
if (result == null) {
Intent intent = new Intent(AdvertisingActivity.this,
AdvertisingErrorActivity.class);
intent.putExtra("ad-error", "Error downloading image");
}
adImg.setImageBitmap(result);
super.onPostExecute(result);
}
} …Run Code Online (Sandbox Code Playgroud) 我怎样才能下载一个文件(图像/视频)从我的PHP服务器使用Retrofit2?
我无法在网上找到有关如何进行的任何资源或教程;我发现这篇文章处理了SO上的某个下载错误,但我不太清楚。有人能指出我正确的方向吗?
这是我的代码:
文件下载服务.java
public interface FileDownloadService {
@GET(Constants.UPLOADS_DIRECTORY + "/{filename}")
@Streaming
Call<ResponseBody> downloadRetrofit(@Path("filename") String fileName);
}
Run Code Online (Sandbox Code Playgroud)
MainActivity.java(@Blackbelt的解决方案)
private void downloadFile(String filename) {
FileDownloadService service = ServiceGenerator
.createService(FileDownloadService.class, Constants.SERVER_IP_ADDRESS);
Call<ResponseBody> call = service.downloadRetrofit("db90408a4bb1ee65d3e09d261494a49f.jpg");
call.enqueue(new Callback<ResponseBody>() {
@Override
public void onResponse(final Response<ResponseBody> response, Retrofit retrofit) {
try {
InputStream is = response.body().byteStream();
FileOutputStream fos = new FileOutputStream(
new File(Environment.getExternalStorageDirectory(), "image.jpg")
);
int read = 0; …Run Code Online (Sandbox Code Playgroud) 我有一个PersonFactory如下界面:
@FunctionalInterface
public interface PersonFactory<P extends Person> {
P create(String firstname, String lastname);
// Return a person with no args
default P create() {
// Is there a way I could make this work?
}
}
Run Code Online (Sandbox Code Playgroud)
本Person类:
public class Person {
public String firstname;
public String lastname;
public Person() {}
public Person(String firstname, String lastname) {
this.firstname = firstname;
this.lastname = lastname;
}
}
Run Code Online (Sandbox Code Playgroud)
我希望能够Person像这样实例化我的:
PersonFactory<Person> personFactory = Person::new;
Person p = personFactory.create(); // …Run Code Online (Sandbox Code Playgroud) java java-8 functional-interface method-reference constructor-reference
我有RecyclerView如下图所示:
这是以下设置代码RecyclerView:
RecyclerView.LayoutManager layoutManager = new GridLayoutManager(this, 2);
dataRecyclerView.setLayoutManager(layoutManager);
dataRecyclerView.addItemDecoration(new GridSpacingItemDecoration(...);
dataRecyclerView.setItemAnimator(new DefaultItemAnimator());
Run Code Online (Sandbox Code Playgroud)
在开始我更新RecyclerView的选定项目的新活动后,RecyclerView将重新填充新数据以反映新的更改,但我得到以下结果:
当我向下滚动时,我得到了这个差距:
我打过电话RecyclerView#invalidate(),#invalidateItemDecorations(),#requestLayout()刷新后,但无济于事; 而且我也没有打电话setHasFixedSize(true)给RecyclerView.
究竟是什么问题?我如何调整子项目的大小,以便在刷新后准确包装其内容?
(PS:我尝试刷新而没有做任何改动而且没有发生任何事情,这证明了我的理论,即只有在儿童用品的高度发生变化时才会出现问题.)
我正在 Android WebView 上加载以下页面: URL
这是加载页面的概述。
我正在尝试在重置按钮上添加点击侦听器。该按钮没有,id但有一个name='resetbutton',因此我尝试使用 来获取对它的引用document.getElementsByName('resetbutton')[0],正如您在上面的屏幕截图中看到的那样,它应该可以工作。
问题是,当我将事件侦听器附加到输入时,它不会触发。这是我的客户端代码:
mWebview.settings.apply {
javaScriptEnabled = true
domStorageEnabled = true
}
WebView.setWebContentsDebuggingEnabled(true)
mWebview.webViewClient = object : WebViewClient() {
override fun onPageFinished(view: WebView?, url: String?) {
super.onPageFinished(view, url)
mWebview.evaluateJavascript("javascript:document.getElementsByName('resetbutton')[0].addEventListener('click', function() {\n" +
" Android.onSubmit('CLICK', 'ED');});") {
Toast.makeText(this@GuestBookActivity, "Got $it", Toast.LENGTH_LONG).show()
}
}
}
mWebview.addJavascriptInterface(GuestBookWebInterface(this), "Android")
mWebview.loadUrl("http://users4.smartgb.com/g/g.php?a=s&i=g44-71854-e8")
Run Code Online (Sandbox Code Playgroud)
GuestBookWebInterface.kt
class GuestBookWebInterface(private val mContext: Context) {
@JavascriptInterface
fun onSubmit(name: String, message: String) {
Log.i("webhook", "Name: $name, message: $message")
}
} …Run Code Online (Sandbox Code Playgroud) 我有一个NavigationView嵌套在DrawerLayout.
活动_main.xml
<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer_layout"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
.......
<android.support.design.widget.NavigationView
android:id="@+id/navigation_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="@layout/drawer_header"
app:menu="@menu/drawer"/>
</android.support.v4.widget.DrawerLayout>
Run Code Online (Sandbox Code Playgroud)
drawer_header.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="150dp"
android:background="?attr/colorPrimaryDark"
android:gravity="bottom"
android:orientation="vertical"
android:padding="16dp"
android:theme="@style/ThemeOverlay.AppCompat.Dark">
<TextView
android:id="@+id/drawerHeaderTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/drawer_header_text"
android:textAppearance="@style/TextAppearance.AppCompat.Body1"/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
如何在 Java 代码中访问抽屉标题的标题?我试过了:
直接使用它的id(drawerHeaderTitle)访问它,但我得到了NullPointerException
通过访问它NavigationView.findViewById:相同的错误
我怎样才能克服这个问题?
我正在业余时间制作一个简单的记事本应用程序,我添加了一些按钮来添加一些文本,例如时间或论文计划等。我目前正在使用代码
textArea.setText("Text");
但它不断替换所有文本,有没有办法将文本添加到 JTextArea 中?我试过了
textArea.addText("Text");
Run Code Online (Sandbox Code Playgroud)
这似乎不起作用。
我想创建一个JSONObject像这样的:
[
{
id:01,
name:"John",
number:010
},
{
id:02,
name:"Mike",
number: 020
}
]
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
public void equipmentViewed(List<Equipment> equipmentSelected, final OnControlResponseListener listener, String description, Equipment equipment) throws JSONException {
wsAccessControl = WSAccessControl.getInstance();
EquipmentViewed equipmentViewed = new EquipmentViewed();
equipmentViewed.setEquipment(equipmentsCount(equipmentSelected));
JSONObject jsonObject = new JSONObject();
try {
jsonObject.put("", new JSONArray(equipmentViewed.getEquipment().toString()));
} catch (JSONException e) {
Log.e(TAG, "Failed to create json object. Cause: " + e.getMessage());
}
String url = Constants.PROVIDER_DOMAIN_URL + Constants.REQUEST_EQUIPMENT;
wsAccessControl.makeWSRequest(RequestType.POST, url, jsonObject, new Response.Listener<String>() {
@Override
public …Run Code Online (Sandbox Code Playgroud)