Java IO笔记

	public static void main(String[] args) throws IOException {
		//输入流
		InputStream in = Test.class.getResourceAsStream("/test");
		InputStreamReader isr = new InputStreamReader(in);
		BufferedReader reader = new BufferedReader(isr);
		
		//输出流
		String resource = Test.class.getResource("/").toString();
		resource = resource.substring(5);
		File fw = new File(resource+"writer.txt");
		BufferedWriter writer = new BufferedWriter(new FileWriter(fw));
		
		int re;
		while((re = reader.read())!=-1){
			System.out.print((char)re);
			writer.write(re);
		}
		
		//刷新缓冲区,将缓冲区剩余的数据写入文件
		writer.flush();
		writer.close();
		
		isr.close();
		in.close();
	}

 

你可能感兴趣的:(java)