using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace _8_2
{
class Program
{
static void Main(string[] args)
{
//用StreamReader和StreamWriter来读取流和写入流
string path = @"E:\ccc\bbb\11.jpg";
StreamReader tr = new StreamReader(path);
string str;
while ((str = tr.ReadLine() )!= null)
{
Console.WriteLine(str);
//str = Console.WriteLine();
}
//Console.WriteLine(str = tr.ReadToEnd());
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace _8_2
{
class Program
{
static void Main(string[] args)
{
//用StreamReader和StreamWriter来读取流和写入流
string path = @"E:\ccc\bbb\11.jpg";
StreamReader tr = new StreamReader(path);
string str;
while ((str = tr.ReadLine() )!= null)
{
Console.WriteLine(str);
//str = Console.WriteLine();
}
//Console.WriteLine(str = tr.ReadToEnd());
tr.Close();
//写入流
StreamWriter sw = new StreamWriter(path);
sw.Write(str+"ddf");//原来的内容和新的内容
sw.Close();
//注意每次都要关闭读入流和写入流
Stream str = Stream.Null;
FileStream fs = new FileStream(path, FileMode.OpenOrCreate);
byte[] by = new byte[50000];
Console.WriteLine(fs.Read(by, 0, 50000));
//FileStream fs1 = File.OpenWrite(@"E:\ccc\bbb\11.txt");
FileStream fs1 = new FileStream(@"E:\ccc\bbb\88.jpg", FileMode.OpenOrCreate);
//我们建个空的图像88.jpg用来将11.jpg写入。
byte[] by1 = new byte[50000];
fs1.Read(by1, 0, 50000);
fs1.Write(by, 0, by.Length);
fs1.Close();
fs.Close();
fs.Close();
通过此应用我们可以把图像存入数据库,需要时可以从数据库中读出。
}
}
}
}
}
}
转载于:https://blog.51cto.com/zhjjzhjj/365843