How to operate in 1,java:
Import java.io.*;
public class Fileinputstreamtest
{public
static void Main (string[] args) throws IOException
{
// Create byte input stream
FileInputStream fis = new FileInputStream ("Fileinputstreamtest.java");
Create a bamboo byte[with a length of 1024
] bbuf = new byte[1024];
The number of bytes to save the actual read
int hasread = 0;
Use loops to repeat the process of fetching while
((Hasread = Fis.read (bbuf)) >0)
{
//Remove "bamboo" (bytes), and convert a byte array into a string input
System.out.println (New String (Bbuf,0,hasread));
Fis.close ();
}
Import java.io.*;
public class Filereadertest
{public
static void Main (string[] args) throws IOException
{
FileReader fr = null;
Try
{
//create character input stream
fr = new FileReader ("Filereadertest.java");
Create a length of 32 "Bamboo tube"
char[] cbuf = new CHAR[32];
The number of characters used to save the actual read
int hasread = 0;
Use loops to repeat the process of fetching while
((Hasread = Fr.read (cbuf)) >0)
{
//Remove "bamboo" (bytes), and convert a byte array into a string input
System.out.println (New String (Cbuf,0,hasread));
}
catch (IOException IoE)
{
ioe.printstacktrace ();
}
Finally
{
///close file input stream
if (fr!= null)
{
fr.close ();
}
}}}
How to operate in 2,c#:
*--------------------------------------------------------------------- --*////<summary>///convert stream to byte[]///</summary> public byte[] Streamtobytes (Stream Strea m) {byte[] bytes = new Byte[stream.
Length]; Stream. Read (bytes, 0, bytes.
Length); Sets the position of the current stream as the start stream of the stream.
Seek (0, seekorigin.begin);
return bytes;
///<summary>///convert byte[] to Stream///</summary> public Stream bytestostream (byte[] bytes) {
Stream stream = new MemoryStream (bytes);
return stream; }/*------------------------------------------------------------------- --*////<summary>///writes stream to file///</summary> public void Streamtofile (stream stream,string FileName) {//convert Stream to byte[] byte[] bytes = new Byte[stream.
Length]; Stream. Read (bytes, 0, bytes.
Length); Sets the current stream's position as the start of the stream strEam.
Seek (0, seekorigin.begin);
Write byte[] to file FileStream fs = new FileStream (FileName, FileMode.Create);
BinaryWriter bw = new BinaryWriter (FS); Bw.
Write (bytes); Bw.
Close (); Fs.
Close ();
///<summary>///reads stream///</summary> public stream filetostream from file (string fileName) {
Open file FileStream FileStream = new FileStream (FileName, FileMode.Open, FileAccess.Read, FileShare.Read);
Read the file byte[] byte[] bytes = new Byte[filestream.length]; FileStream.Read (bytes, 0, bytes.
Length);
Filestream.close ();
Convert byte[] into stream stream stream = new MemoryStream (bytes);
return stream; }
The above is a small series for everyone to bring Java and C # input and Output flow method (detailed) All content, I hope that we support cloud-Habitat Community ~