テキストを1行ずつ読み取り、文字列バッファーに5000ワードごとに文字列バッファーを埋めるサーブレット言語を使用した私のコードは、jspページにコンテンツを表示し、ヘッダー表示テキストをutf-8に入れます。問題は、テキストがコードをutf-8エンコーディングするとunknown文字で読み取られ、コードでテキストをutf-8で読み取り、utf-8エンコーディングでユーザーに表示されるテキストがテキストを読み取るためのコードです
try{
File file = new File(p);
l = (int) file.length();
String s = null,strr=null;
String g = null,m=null;
int i = 0;
Scanner input = new Scanner(file);
s1 = new StringBuffer();
s2 = new StringBuffer();
while (input.hasNextLine()) {
g = input.nextLine();
String[] d = g.split(" ");
int h = d.length;
i = i + h;
if (i > 5000) {
break;
}
s1.append(g).append(System.getProperty("line.separator"));
}
if(i > 5000) {
s2.append(g).append(System.getProperty("line.separator"));
while( input.hasNextLine()) {
s = input.nextLine();
String[] d = s.split(" ");
int h = d.length;
i=0;
i=i+h;
if (i > 5000) {
break;
}
s2.append(s).append(System.getProperty("line.separator"));}
if (input.hasNextLine()) {
s3.append(s).append(System.getProperty("line.separator"));
while(input.hasNextLine()) {
strr = input.nextLine();
s3.append(strr).append(System.getProperty("line.separator"));
}
}
}
input.close();
} catch (Exception e) {
e.getMessage();
}