JAVA_从输入流中获取文件名称

/**
* 从输入流中获取文件名称
*
* @param URL
* @return NAME
*/
public static String getFileNameFromUrl(String url) {

String name = new Long(System.currentTimeMillis()).toString() + ".X";
int index = url.lastIndexOf("/");
if (index > 0) {
name = url.substring(index + 1);
if (name.trim().length() > 0) {
return name;
}
}
return name;
}

/**
* 从输入流中获取字节数组
*
* @param inputStream
* @return
* @throws IOException
*/
public static byte[] readInputStream(InputStream inputStream)
throws IOException {
byte[] buffer = new byte[1024];
int len = 0;
ByteArrayOutputStream bos = new ByteArrayOutputStream();
while ((len = inputStream.read(buffer)) != -1) {
bos.write(buffer, 0, len);
}
bos.close();
return bos.toByteArray();
}

posted @ 2018-03-30 15:15  谷香香  阅读(706)  评论(0)    收藏  举报