アセットフォルダにXMLファイルがあります。XMLファイルは問題なくオブジェクトに解析されます(つまり、XMLは100%正しいことを意味します)。
今私がしているのは、XMLファイルをアセットフォルダーから内部ストレージにコピーすることです。コピーしたXMLファイルを内部メモリから開こうとすると、常に例外が発生します。
org.jdom.input.JDOMParseException: Error on line 660: At line 660, column 8: not well-formed (invalid token)
この行を呼び出すとき:
Document doc = (Document) builder.build(xmlStream); (Where xmlStream is InputStream argument)
xmlStream
-argumentを取得し、Stringに変換して画面に出力したため、ファイルは問題なくコピーされたようです。見た目は問題ありません。ここで重要なのは、例外は常にファイルの最後の位置が間違っていることを示しているということです。したがって、ファイルの下部にある終了タグの最後の文字は、行660col8にある'>'です。
コピー操作
public class InternalMemory {
private static Context mContext;
public static String INTERNAL_PATH;
static {
mContext = App.getContext();
INTERNAL_PATH = mContext.getApplicationContext().getFilesDir().toString();
}
public static void SaveStream(InputStream is,String folder,String fileName) {
String path = INTERNAL_PATH + "/"+folder+"/";
File file = new File(path);
file.mkdirs();
path += fileName;
OutputStream os;
try {
os = new BufferedOutputStream(new FileOutputStream(path,true));
write(is,os);
os.flush();
os.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
private static void write(InputStream in, OutputStream out) throws IOException {
byte[] buffer = new byte[1024];
int read;
while((read = in.read(buffer)) != -1){
out.write(buffer, 0, read);
}
}
}