`
chenzhaomin
  • 浏览: 10225 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

IO(using English)

    博客分类:
  • Java
 
阅读更多

  This is my first write blog in english,maybe it has some errors,so,I hope reader can point the problem,I will modified it.

  Now,I will talk about the IO in java。You know IO is the important aspect,not only in java,but also in every computer language。We will use IO to read something   or write something from files. 

   In java,IO can divide into two aspect,one is input stream and output stream。Another is character stream and byte stream。They are not different,just in two statement。

   And in java api,we can use many class to help us to complete many operation on files.It is very easy to use this class,you can refer to the api。But we must pay attention to one thing。Buffer stream is different from the other,because when you use BufferedOutputStream to write information in file,it first reserved this in buffer,so if the program is terminated,the information will lost。we can use flush() to solve this problem。Do not forget use close() to close this stream,we need economize memory.

 

package cn.czm0910;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

public class FileDemo {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		try {
			fileReadWrite("a.txt","b.txt");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	/**
	 * 文件读取
	 * @param path
	 * @throws IOException 
	 */
	public static void fileReadWrite(String path1,String path2) throws IOException{
		FileInputStream fis = new FileInputStream(path1);
		FileOutputStream fos = new FileOutputStream(path2);
		BufferedInputStream bis = new BufferedInputStream(fis);
		BufferedOutputStream bos = new BufferedOutputStream(fos);
		//byte[] buf=new byte[1024];
		int i=0;
		System.out.println(fis.available());
		while((i=bis.read())!=-1){
			bos.write(i);
			bos.flush();
		}
		fis.close();
		fos.close();
	}

}

 

分享到:
评论

相关推荐

    Vue.js 2 Cookbook

    English | 28 Apr. 2017 | ASIN: B01N6VAO4P | 454 Pages | AZW3 | 7.38 MB Key Features Understand and use Vue's reactivity system, data binding, and computed properties Create fluid transitions in your...

    C#读写INI文件(Word)

    using System.IO; using System.Runtime.InteropServices; using System.Text; using System.Collections; using System.Collections.Specialized; namespace wuyisky { public class IniFiles { public string ...

    TestFileSystemWatcher

    using System.IO; class Program { static void Main() { FileSystemWatcher watcher = new FileSystemWatcher(); watcher.Path = Directory.GetCurrentDirectory(); watcher.Filter = "*.txt"; watcher....

    如何开发一个多种语言版本的C#程序

    using System.IO; ``` 然后,在Form1类中,定义CultureInfo对象(ci)和ResourceManager对象(rm),用于处理语言切换和获取资源: ```csharp private CultureInfo ci; private ResourceManager rm; ``` 当用户选择...

    C#使用Microsoft Office Document Imaging(MODI)进行开发实例

    using System.IO; using Microsoft.Office.Interop.Modi; public class OcrExample { public void RecognizeText(string imagePath) { // 创建MODI文档对象 MDIApplication mdi = new MDIApplication(); mdi....

    Data Science with Java: Practical Methods for Scientists and Engineers

    English | 6 Jun. 2017 | ASIN: B072MKRQBQ | 236 Pages | AZW3 | 2.78 MB Data Science is booming thanks to R and Python, but Java brings the robustness, convenience, and ability to scale critical to ...

    PHP 7 Data Structures and Algorithms

    English | 6 Jun. 2017 | ASIN: B01IF7NLDW | 340 Pages | AZW3 | 2.55 MB Key Features Gain a complete understanding of data structures using a simple approach Analyze algorithms and learn when you ...

    c#利用MODI作图像中文字提取含资源库

    using System.IO; using Microsoft.Office.Interop.MODI; namespace C_Ocr_lib { public class OcrEngine { public string ExtractTextFromImage(string imagePath) { try { MODI.Document doc = new MODI....

    WPF 图片转换文字的MODI组件

    using System.IO; using Microsoft.Office.Interop.MODI; public class MODIHelper { public static string ImageToText(string imagePath) { try { // 初始化MODI环境 MODI.Document doc = new MODI....

    Single Page Web Applications JavaScript end-to-end

    Single Page Web Applications shows how your team can easily design, test, maintain, and extend sophisticated SPAs using JavaScript end-to-end, without getting locked into a framework. Along the way, ...

    Angular Router

    English | 20 Mar. 2017 | ASIN: B06X9N272Y | 118 Pages | AZW3 | 2.44 MB Key Features Written by the creator of the Angular router, giving you the best information straight from the source Get full ...

    软件测试系列--软件测试修炼之路

    6. **http://seg.iit.nrc.ca/English/index.html**:位于加拿大的软件工程质量研究组织,提供了一系列研究论文的下载服务,适合于那些希望深入了解软件质量管理和控制的专业人士。 7. **http://sepo.nosc.mil/**:...

    Clubify-crx插件

    https: //help.clubhouse.io/hc/zh-CN/articles/207540323-Using-the-Clubhouse-GitHub-Integration-with-Branches-and-Pull-Requests这是JIRAfy的修改后的分叉:https:// github com / square / jirafy 支持语言...

    C#读写INI文件的方法

    using System.IO; using System.Runtime.InteropServices; using System.Text; using System.Collections; using System.Collections.Specialized; public class IniFiles { public string FileName; [DllImport...

    C#winform实现界面多语言切换

    using System.IO; using System.Xml; // 加载XML文件 string xmlPath = "LanguageResources.xml"; XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(xmlPath); // 创建一个字典存储每种语言的资源 Dictionary...

    基于 Gin 进行模块化设计的 API 框架,封装了常用功能,使用简单,致力于进行快速的业务研发.zip

    - English Document:[en.md](/blob/master/en.md) ## 轻量版 为了满足开发者对于简单、轻量级 API 框架的需求,开发了 gin-api-mono,旨在提供更便捷的业务开发体验。 相比于 go-gin-api,首先 gin-api-mono ...

    如何:使用C#使用Office 2007 OCR

    using System.IO; using Microsoft.Office.Interop.MODI; public class OcrProcessor { public string ProcessImage(string imagePath) { // 初始化MODI环境 MODI.Document doc = new MODI.Document(); try {...

    Packt.Python.Journey.from.Novice.to.Expert.2016

    Chapter 7: Async IO – Multithreading without Threads Chapter 8: Metaclasses – Making Classes (Not Instances) Smarter Chapter 9: Documentation – How to Use Sphinx and reStructuredText Chapter 10: ...

Global site tag (gtag.js) - Google Analytics