有一个在线文件(例如http://www.example.com/information.asp)我需要抓取并保存到目录中.我知道有几种方法可以逐行获取和读取在线文件(URL),但有没有办法只使用Java下载和保存文件?
Google 正在弃用 Android 11 中的 Android AsyncTask API,并建议java.util.concurrent改用。你可以在这里查看提交
*
* @deprecated Use the standard <code>java.util.concurrent</code> or
* <a href="https://developer.android.com/topic/libraries/architecture/coroutines">
* Kotlin concurrency utilities</a> instead.
*/
@Deprecated
public abstract class AsyncTask<Params, Progress, Result> {
Run Code Online (Sandbox Code Playgroud)
如果您在 Android 中维护带有异步任务的旧代码库,则将来可能需要对其进行更改。我的问题是,使用java.util.concurrent. 它是一个 Activity 的静态内部类。我正在寻找可以使用的东西minSdkVersion 16
private static class LongRunningTask extends AsyncTask<String, Void, MyPojo> {
private static final String TAG = MyActivity.LongRunningTask.class.getSimpleName();
private WeakReference<MyActivity> activityReference;
LongRunningTask(MyActivity context) {
activityReference = new WeakReference<>(context);
}
@Override
protected MyPojo doInBackground(String... params) { …Run Code Online (Sandbox Code Playgroud) 我希望能够获取一个网页的html并将其保存到一个String,所以我可以对它进行一些处理.另外,我如何处理各种类型的压缩.
我将如何使用Java进行此操作?
我正在使用URL.openConnection()从服务器下载的东西.服务器说
Content-Type: text/plain; charset=utf-8
Run Code Online (Sandbox Code Playgroud)
但connection.getContentEncoding()回报null.怎么了?