1. Java의 작동 방법 :
java.io.*; public class fileInputStreamTest {public static void main (string [] args)은 ioexception {// Byte 입력 스트림 생성 FileInputStream fis = new FileInputStream ( "FileInputStreamTest.java"); // 길이 1024 바이트를 가진 대나무 튜브를 만듭니다 [] bbuf = new Byte [1024]; // 루프를 사용하여 "물 철수"프로세스를 반복하여 ((hasread = fis.read (bbuf))> 0) {// "대나무 튜브"(바이트)를 꺼내어 바이트 배열을 문자열로 변환하고 System.out.println (새 문자열 (bbuf, 0, hasread)); } fis.close (); }} java.io.*; public class filereadertest {public static void main (String [] args)은 ioexception {filereader fr = null; 시도 {// 문자 입력 스트림 생성 fr = new Filereader ( "FilerEaderTest.java"); // 길이 32 char [] cbuf = new char [32]를 가진 "대나무 튜브"를 만듭니다. // 루프를 사용하여 "물 철수"프로세스를 반복하여 ((hasread = fr.read (cbuf))> 0) {// "대나무 튜브"(바이트)를 꺼내어 바이트 배열을 문자열로 변환하고 System.out.println (새 문자열 (cbuf, 0, hasread)); }} catch (ioexception ioe) {ioe.printstacktrace (); } 마지막으로 {// 파일 입력 스트림을 닫습니다. if (fr! = null) {fr.close (); }}}}}}}}2. C#의 작동 방법 :
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ /// <summary> /// Convert Stream to byte[] /// </summary> public byte[] StreamToBytes(Stream stream) { byte[] bytes = new 바이트 [stream.length]; stream.read (바이트, 0, 바이트 길이); // 스트림의 현재 위치를 스트림의 시작 부분으로 설정합니다 (0, seekorigin.begin); 반환 바이트; } /// <summary> /// byte []를 스트림으로 convert /// </summary> public stream bytestostream (byte [] bytes) {stream stream = new MemoryStream (bytes); 리턴 스트림; }/ * ---------------------------------------------------- * 스트림과 파일 사이의 전환 * -------------------------------- * // // <summary> // </void to </void to/void thream. 스트림, 문자열 filename) {// 스트림을 바이트 [] byte [] bytes로 변환 = new Byte [stream.length]; stream.read (바이트, 0, 바이트 길이); // 스트림 스트림의 시작 부분으로 현재 스트림 위치를 설정합니다. // 파일에 byte []를 쓰기 FILESTREAM FS = NEW FILESTREAM (filename, filemode.create); BinaryWriter BW = New BinaryWriter (FS); bw.write (바이트); bw.close (); fs.close (); } /// <summary> /// 파일에서 스트림 읽기 /// </summary> public stream filetoStream (String filename) {// filestream filestream = new Filestream (filename, filemode.open, fileAccess.Read, fileshare.Read); // 파일 바이트 읽기 [] byte [] bytes = new Byte [filestream.length]; filestream.Read (바이트, 0, 바이트 길이); filestream.close (); // byte []을 스트림 스트림으로 변환하시는 스트림 = 새 memorystream (bytes); 리턴 스트림; }위의 것은 Java 및 C# 입력 및 출력 스트림 메소드 (세부 설명)의 전체 내용입니다. 모두가 wulin.com을 더 지원하기를 바랍니다