xg西戈 2021-06-14 16:31 采纳率: 0%
浏览 622

cannot be resolved to a type

public class FileUtils02 {
	public static void main(String[] args) {
		//文件到文件
		try {
			InputStream is = new FileInputStream("abc.txt");
			OutputStream os = new FileOutputStream("abc-copy.txt");
			copy(is, os);
		} catch (IOException e) {
			e.printStackTrace();
		}
		//文件到字节数组
		byte[] datas = null;
		try {
			InputStream is = new FileInputStream("1.jpg");
			ByteArrayOutputStream os = new ByteArrayOutputStream();
			copy(is, os);
			datas = os.toByteArray();
			System.out.println(datas);
		} catch (IOException e) {
			e.printStackTrace();
		}
		//字节数组到文件
		try {
			InputStream is = new ByteArrayInputStream(datas);
			OutputStream os = new FileOutputStream("1-copy.jpg");
			copy(is, os);
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		int g = 1;
		
	}
	/*
	 * 对接输入输出流
	 * try...with...resource
	 */
	
	public static void copy(InputStream is,OutputStream os) {
		try(is;os) {
		 	//3、操作(分段读取 )
			byte[] flush = new byte[1024];  //缓冲容器
			int len = -1;  //接受长度
			while ((len = is.read(flush))!=-1) {
				os.write(flush, 0, len);  //分段写出
			}
			os.flush();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) { 
			e.printStackTrace();
		}
	}
}

其中这个地方显示is cannot be resolved to a type问题

新手学习代码感觉没有什么问题,但是不知道具体怎样解决,请路过的大神指点迷津,万分感谢!

  • 写回答

2条回答 默认 最新

  • CSDN专家-Time 2021-06-14 16:33
    关注

    不能解析为一个类型,检查一下类型有没有定义。

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#python#的问题:我知道这个问题对你们来说肯定so easy
  • ¥15 wpf datagrid如何实现多层表头
  • ¥15 为啥画版图在Run DRC会出现Connect Error?可我Calibre的hostname和计算机的hostname已经设置成一样的了。
  • ¥20 网站后台使用极速模式非常的卡
  • ¥20 Keil uVision5创建project没反应
  • ¥15 mmseqs内存报错
  • ¥15 vika文档如何与obsidian同步
  • ¥15 华为手机相册里面的照片能够替换成自己想要的照片吗?
  • ¥15 陆空双模式无人机飞控设置
  • ¥15 sentaurus lithography