这是我正在使用的代码
import android.content.res.AssetManager;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.Html;
import android.util.Log;
import android.webkit.WebView;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.List;
import nl.siegmann.epublib.domain.Book;
import nl.siegmann.epublib.domain.TOCReference;
import nl.siegmann.epublib.epub.EpubReader;
public class MainActivity extends AppCompatActivity {
WebView webview;
String line, line1 = "", finalstr = "";
int i = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webview = findViewById(R.id.web_view);
AssetManager assetManager = getAssets();
String javascrips = "";
try {
InputStream input = this.getAssets().open(
"adventures.epub");
int size;
size = input.available();
byte[] buffer = new byte[size/10000];
input.read(buffer);
input.close();
javascrips = new String(buffer);
} catch (IOException e) {
e.printStackTrace();
}
webview.loadDataWithBaseURL("file:///android_asset/", javascrips,
"application/epub+zip", "UTF-8", null);
}
@SuppressWarnings("unused")
private void logTableOfContents(List<TOCReference> tocReferences, int depth) {
if (tocReferences == null) {
return;
}
for (TOCReference tocReference : tocReferences) {
StringBuilder tocString = new StringBuilder();
for (int i = 0; i < depth; i++) {
tocString.append("\t");
}
tocString.append(tocReference.getTitle());
Log.i("TOC", tocString.toString());
try {
InputStream is = tocReference.getResource().getInputStream();
BufferedReader r = new BufferedReader(new InputStreamReader(is));
while ((line = r.readLine()) != null) {
Log.v("line" + i, Html.fromHtml(line).toString());
line1 = line1.concat(Html.fromHtml(line).toString());
}
finalstr = finalstr.concat("\n").concat(line1);
i++;
} catch (IOException e) {
}
logTableOfContents(tocReference.getChildren(), depth + 1);
}
webview.loadDataWithBaseURL("", finalstr, "text/html", "UTF-8", "");
}
}
我正在将我的网页视图中的输出视为
onCreate:PK sGoa,mimetypeapplication / epub的+ zipPKsGKU META-INF / container.xml中] 0 *5z X &gt; @L LwC “g of zq 。:&amp; Y ) xTZ DA
我接受了我的动机和我的关系中的空白网页视图
答案 0 :(得分:0)
这应该是编码格式转换错误,您不必尝试转码。或者获取文本编码格式,使用此文本编码格式转换utf-8