当前位置:首页 > 开发 > 编程语言 > Java IO > 正文

java io

发表于: 2012-05-12   作者:blackproof   来源:转载   浏览:
摘要: java输入输出流,图:http://blog.sina.com.cn/s/blog_855ce96b0100vr7r.html   字节输入输出代码:       public static void main(String[] arg) { try { File f = new File("D:\\proje

java输入输出流,图:http://blog.sina.com.cn/s/blog_855ce96b0100vr7r.html

 

字节输入输出代码:

 

 

 

public static void main(String[] arg)
	{
		try
		{
			File f = new File("D:\\project\\EclipseWorkSpace\\jsfdemo\\src\\testIo");
			InputStream infile = new FileInputStream(f);
			byte[] b = new byte[(int) f.length()];
			infile.read(b);
			infile.close();
			System.out.println(new String(b));
			
			OutputStream outfile = new FileOutputStream(new File("D:\\project\\EclipseWorkSpace\\jsfdemo\\src\\testIo"));
			String context = new String(b);
			context += "\nFinish";
			b = context.getBytes();
			outfile.write(b);
			outfile.close();
		}
		catch(Exception ex)
		{
			ex.printStackTrace();
		}
	}

 

字符输入输出代码:

 

public static void main2(String[] arg)
	{
		try
		{
			FileInputStream infile = new FileInputStream(new File("D:\\project\\EclipseWorkSpace\\jsfdemo\\src\\testIo"));
			BufferedReader in = new BufferedReader(new InputStreamReader(infile));
			String context = "";
			String s;
			while((s = in.readLine())!= null && s.length()!=0)
			{
				context += s;
				System.out.println(context);
			}
			in.close();
			
			//write context to file
			FileOutputStream outfile = new FileOutputStream(new File("D:\\project\\EclipseWorkSpace\\jsfdemo\\src\\testIo"));
			PrintWriter pw = new PrintWriter(outfile);
			pw.print(context);
			pw.print("\n");
			pw.println("finished");
			pw.println("finished??");
			
			pw.close();
		}
		catch(IOException e){ e.printStackTrace();}
	}

java io

  • 0

    开心

    开心

  • 0

    板砖

    板砖

  • 0

    感动

    感动

  • 0

    有用

    有用

  • 0

    疑问

    疑问

  • 0

    难过

    难过

  • 0

    无聊

    无聊

  • 0

    震惊

    震惊

我来说两句
评论内容:
验  证  码:
 
(网友评论仅供其表达个人看法,并不表明本站同意其观点或证实其描述。)
评论列表
已有 0 条评论(查看更多评论)
版权所有 IT知识库 CopyRight © 2009-2015 IT知识库 IT610.com , All Rights Reserved. 京ICP备09083238号