自动化__持续集成___java___文本文件__字节流

Posted 18513757531

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了自动化__持续集成___java___文本文件__字节流相关的知识,希望对你有一定的参考价值。

一、代码如下

package www.wujianbotwo;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

public class Demo09 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Demo09 demo09= new Demo09();
		demo09.byteRead();

	}
	
	private void byteRead() {
		try {
			File file= new File("D:\\Test.txt");
			InputStream in= new FileInputStream(file);
			byte[] buf= new byte[(int)file.length()];
			in.read(buf);
			in.close();
			for(byte b: buf) {
				System.out.println(b);
			}
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		

	}

}

 

package www.wujianbotwo;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public class Demo09 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Demo09 demo09= new Demo09();
		//demo09.byteRead();
		demo09.byteWrite();
		demo09.byteWriteFalse();

	}
	
	private void byteRead() {
		try {
			File file= new File("D:\\Test.txt");
			InputStream in= new FileInputStream(file);
			byte[] buf= new byte[(int)file.length()];
			in.read(buf);
			in.close();
			for(byte b: buf) {
				System.out.println(b);
			}
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		

	}
	
	private void byteWrite() {
		try {
			File file= new File("D:\\Test.txt");
			OutputStream out= new FileOutputStream(file, true);
			String content= "这是文件内容。\r\n";
			byte[] buf= content.getBytes();
			out.write(buf, 0, buf.length);
			out.close();
			System.out.println("输入成功!!");
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}
	
	
	private void byteWriteFalse() {
		try {
			File file= new File("D:\\Test.txt");
			OutputStream out= new FileOutputStream(file, false);
			String content= "这是文件内容。\r\n";
			byte[] buf= content.getBytes();
			out.write(buf, 0, buf.length);
			out.close();
			System.out.println("输入成功!!");
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}


}

 

以上是关于自动化__持续集成___java___文本文件__字节流的主要内容,如果未能解决你的问题,请参考以下文章

自动化__持续集成___java___继承

自动化__持续集成___java___finally

自动化__持续集成___java___List

自动化__持续集成___java___取值范围

自动化__持续集成___java___数据类型转换

自动化__持续集成___java___字符串