-1
私の目標は、別のファイルからファイルの内容を削除することです。これらのファイルはHttpURLConnectionを介してアクセスできます。入力ストリームの最後からNバイトを削除します
私の考えは、最初のファイルからコンテンツの長さを取得することです。このコンテンツの長さをNとしましょう。また、2番目の入力ストリーム(file2)Nバイトから削除します。
HttpURLConnection connection1 = (HttpURLConnection) url1.openConnection();
HttpURLConnection connection2 = (HttpURLConnection) url2.openConnection();
String contentLength1 = connection1.getHeaderFields().get("Content-Length").get(0);
String contentLength2 = connection2.getHeaderFields().get("Content-Length").get(0);
InputStream is = connection2.getInputStream();
EDIT:
私はより良い方法があるかどうか、私は疑問に思う、それを行うための方法を発見しました。
ByteArrayOutputStream into = new ByteArrayOutputStream();
byte[] buf = new byte[4096];
for (int n; 0 < (n = is.read(buf));) {
into.write(buf, 0, n);
}
into.close();
byte[] data = into.toByteArray();
int length1 = Integer.parseInt(contentLength1);
int length2 = Integer.parseInt(contentLength2);
byte[] newData = new byte[length2-length1];
System.arraycopy(data, 0, newData, 0, newData.length);
ByteArrayInputStream newStream = new ByteArrayInputStream(newData);
プラットフォームにタグを付けてください。質問が広すぎる限り、あなたが試したことを示してください。http://stackoverflow.com/help/how-to-ask – EJoshuaS
@Yassine Javaでコーディングしていますか?これは私が知っている唯一の一般的な言語で、標準ライブラリの一部として 'HttpURLConnection'クラスを持っています。関連するコードを提示してください。 – callyalater
私の質問を編集して、私の問題についての詳細な情報を提供しました – Yassine