1。Javaの操作方法:
java.io.*をインポートします。 public class fileinputStreamTest {public static void main(string [] args)throws ioexception {// Byte input Stream FileInputStream fis = new FileInputStream( "FileInputStreamTest.java"); //長さ1024バイトで竹のチューブを作成します[] bbuf = new byte [1024]; //ループを使用して「水の撤退」プロセスを繰り返します((hasread = fis.read(bbuf))> 0){//「竹のチューブ」(バイト」(バイト)を取り出し、System.out.out.println(new String(bbuf、0、hasread)); } fis.close(); }} java.io.*をインポートします。 public class fileReadertest {public static void main(string [] args)throws ioexception {filereader fr = null; try {//文字入力ストリームfr = new fileReader( "filereadertest.java"); //長さ32 char [] cbuf = new char [32]で「竹のチューブ」を作成します。 //ループを使用して「水の引き出し」プロセスを繰り返します((hasread = fr.read(cbuf))> 0){//「竹のチューブ」(バイト)を取り出し、バイト配列を文字列に変換し、system.out.out.println(new String(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 byte [stream.length]; stream.read(bytes、0、bytes.length); //ストリームの現在の位置をStream.seek(0、Seekorigin.begin)の先頭に設定します。バイトを返します。 } /// <summary> /// byte []をストリーミングに変換/// </summary> public stream bytestostream(byte [] bytes){stream stream = new MemoryStream(bytes);リターンストリーム。 } /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * Conversion between Stream and file* - - - - - - - - - - - - - - - - - - - - - - - - - * / // // <summary> /// Write Stream to file/// </summary> public void StreamToFile(Stream stream、string filename){//ストリームをbyte [] byte [] bytes = new byte [stream.length]; stream.read(bytes、0、bytes.length); //現在のストリーム位置をStream Stream.seek(0、Seekorigin.begin)の先頭に設定します。 //ファイルにbyte []をfilestream fs = new fileStream(filename、filemode.create)に書き込みます。 BinaryWriter bw = new binarywriter(fs); bw.write(バイト); bw.close(); fs.close(); } /// <summary> ///ファイルからストリームを読む//ファイルを読み取りますbyte [] byte [] bytes = new byte [filestream.length]; fileStream.read(bytes、0、bytes.length); fileStream.close(); // byte []をストリームストリームに変換= new MemoryStream(bytes);リターンストリーム。 }上記は、編集者が提起したJavaおよびC#入力および出力ストリームメソッド(詳細な説明)の完全な内容です。誰もがwulin.comをもっとサポートすることを願っています〜