Wednesday, May 4, 2011

Save RequestStream to file

DataInputStream dataStream = new DataInputStream(req.getInputStream());
byte datas[] = new byte[formDataLength];
int totalBytes = 0;
while (totalBytes < formDataLength) {
int bytes = dataStream.read(datas, totalBytes, formDataLength);
totalBytes += bytes;
}

saveMp3(datas);

public static void saveFile(byte[] datas) throws Exception{
FileOutputStream fileOutputStream = new FileOutputStream("xxxxx");
fileOutputStream.write(datas);
fileOutputStream.flush();
fileOutputStream.close();
}

No comments: