java 中如何将InputStream对象转换为OutputStream对象

postxx 2013-10-09 02:17:20
java 中如何将InputStream对象转换为OutputStream对象
方法签名:
public static OutputStream read(InputStream inStream)
...全文
870 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
postxx 2013-10-09
  • 打赏
  • 举报
回复
引用 5 楼 abstruct 的回复:
System.out.println(Test1.class.getClassLoader().getResource("com/example/xml"));
引用 6 楼 postxx 的回复:
如何获取这个文件的OutputStream 。 InputStream xml = this.getClass().getClassLoader() .getResourceAsStream("com/example/gaga/xml/test3.xml"); // 读取指定路径下的xml
这个怎么实现呀
postxx 2013-10-09
  • 打赏
  • 举报
回复
如何获取这个文件的OutputStream 。
InputStream xml = this.getClass().getClassLoader()
.getResourceAsStream("com/example/gaga/xml/test3.xml"); // 读取指定路径下的xml
安特矮油 2013-10-09
  • 打赏
  • 举报
回复
System.out.println(Test1.class.getClassLoader().getResource("com/example/xml"));
失落夏天 2013-10-09
  • 打赏
  • 举报
回复
//获取当前类路径 String file = ClassLoader.getSystemClassLoader().getResource("").getFile();
postxx 2013-10-09
  • 打赏
  • 举报
回复
引用 2 楼 AA5279AA 的回复:

InputStream in = new FileInputStream(new File("D:\\1.jpg"));
			FileOutputStream fileOut = new FileOutputStream(new File(
					"D:\\2.jpg"));
			byte[] buf = new byte[1024 * 8];
			while (true) {
				int read = 0;
				if (in != null) {
					read = in.read(buf);
				}
				System.out.println(read);
				if (read == -1) {
					break;
				}
				fileOut.write(buf, 0, read);
			}
			fileOut.flush();
我用的文件时放在 包下面的如 com.example.xml 包下面的test.xml ,该如何取得呀
失落夏天 2013-10-09
  • 打赏
  • 举报
回复

InputStream in = new FileInputStream(new File("D:\\1.jpg"));
			FileOutputStream fileOut = new FileOutputStream(new File(
					"D:\\2.jpg"));
			byte[] buf = new byte[1024 * 8];
			while (true) {
				int read = 0;
				if (in != null) {
					read = in.read(buf);
				}
				System.out.println(read);
				if (read == -1) {
					break;
				}
				fileOut.write(buf, 0, read);
			}
			fileOut.flush();
  • 打赏
  • 举报
回复
http://www.cnblogs.com/vigarbuaa/archive/2013/01/13/2858859.html

50,523

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧