当前位置: 首页>>代码示例>>C#>>正文


C# StreamWriter.Flush方法代码示例

本文整理汇总了C#中StreamWriter.Flush方法的典型用法代码示例。如果您正苦于以下问题:C# StreamWriter.Flush方法的具体用法?C# StreamWriter.Flush怎么用?C# StreamWriter.Flush使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在StreamWriter的用法示例。


在下文中一共展示了StreamWriter.Flush方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ClientHandler

    public static void ClientHandler(TcpClient client) {
        var d = new Dictionary<string, ProcessCommand>() {
            { "cat", CatFile },
            { "clx", CalcClx },
            { "erf", CalcErf },
            { "sz", FileSize },
            { "info", GetInfo }
        };

        while (client.Connected) {
            using (var streamReader = new StreamReader(client.GetStream()))
            using (var streamWriter = new StreamWriter(client.GetStream())) {
                var cmd = streamReader.ReadLine().Split(" ".ToCharArray(), 2);

                try {
                    d[cmd[0]](cmd[1], streamWriter);
                }
                catch {
                    streamWriter.WriteLine("Error :(");
                }
                streamWriter.Flush();
            }
        }
        client.Close();
    }
开发者ID:noscripter,项目名称:root-2015-tasks,代码行数:25,代码来源:Program.cs

示例2: MakeFileToRead

 private static void MakeFileToRead(String file, Boolean optional, String dest)
 {
     using (StreamWriter write = new StreamWriter(file))
     {
         if (!optional)
         {
             for (int i = 97; i < 123; i++)
             {
                 write.WriteLine((char)(i));
                 write.Flush();
             }
         }
         else
         {
             using (StreamReader reader = new StreamReader(dest))
             {
                 string line;
                 int br = 1;
                 while ((line = reader.ReadLine()) != null)
                 {
                     write.WriteLine(br + ". " + line);
                     write.Flush();
                     br++;
                 }
             }
         }
     }
 }
开发者ID:Bvaptsarov,项目名称:Homework,代码行数:28,代码来源:Program.cs

示例3: Main

    static void Main(string[] args)
    {
        String n="", horariosOut="";
        IPAddress ip = IPAddress.Parse("127.0.0.1");
        TcpListener tcpListener = new TcpListener(ip, 5050);
        tcpListener.Start();
        Socket serverSock = tcpListener.AcceptSocket();

        if (serverSock.Connected)
        {
            NetworkStream con = new NetworkStream(serverSock);
            //Archivo local en servidor, el cual se activará para mandar un correo
         StreamWriter crearArchivoLocal = new StreamWriter("C:/Users/Dell/Documents/datoAdjunto.txt");

         StreamWriter enviarDatos = new StreamWriter(con);
          StreamReader recibirDatos = new StreamReader(con);

            if(recibirDatos.ReadLine()!=""){
                horariosOut = "Horarios disponibles: 1) 9:00 am  2) 12:00 pm  3) 3:00pm  4) 5:00 pm  5) 12:00 am. Seleccione alguna opción indicando con un numero";
                   enviarDatos.WriteLine(horariosOut);
            enviarDatos.Flush();
                }

            if(recibirDatos.ReadLine().Equals("2")){

                       n = (recibirDatos.ReadLine() );

            crearArchivoLocal.WriteLine(n);

            }

            if(recibirDatos.ReadLine().Equals("3")){
                EnviarEmail enviarCorreo = new EnviarEmail();
                bool exito = enviarCorreo.EnviarMail(recibirDatos.ReadLine(), "Datos de reservación", n, "AerolinasMisael", "[email protected]", "josueupbc");
                if (exito == true)
                {
                    enviarDatos.WriteLine(n + " El correo fue enviado exitosamente");
                    Console.WriteLine("El correo ha sido enviado exitosamente");
                }
                else
                    Console.Error.WriteLine("No fue posible enviar el correo");
                enviarDatos.Flush();

            }

            recibirDatos.Close();
            crearArchivoLocal.Close();
            enviarDatos.Close();
            con.Close();
           serverSock.Close();
        }
        else
            Console.WriteLine("Fallo en la conexion");

        Console.ReadKey();
    }
开发者ID:JosueRodriguezGalindo,项目名称:ProyectoFinal,代码行数:56,代码来源:Servidor.cs

示例4: Main

    static void Main(string[] args)
    {
        NetworkStream stream;
        TcpClient irc;
        string inputLine;
        StreamReader reader;
        string nickname;

        try
        {
            irc=new TcpClient(SERVER,PORT);
            stream=irc.GetStream();
            reader=new StreamReader(stream);
            writer=new StreamWriter(stream);

            PingSender ping=new PingSender();
            ping.Start();

            writer.WriteLine(USER);
            writer.Flush();
            writer.WriteLine("NICK"+NICK);
            writer.Flush();
            writer.WriteLine("JOIN"+CHANNEL);
            writer.Flush();

            while(true)
            {
                while((inputLine=reader.ReadLine())!=null)
                {
                    if(inputLine.EndsWith("JOIN:"+CHANNEL))
                    {
                        nickname=inputLine.Substring(1,inputLine.IndexOf("!")-1);

                        writer.WriteLine("NOTICE"+nickname+":Hi"+nickname+" and welcome to "+CHANNEL+" channel! ");
                        writer.Flush();

                        Thread.Sleep(2000);
                    }
                }

                writer.Close();
                reader.Close();
                irc.Close();
            }
        }

        catch(Exception e)
        {
            Console.WriteLine(e.ToString());
            Thread.Sleep(5000);
            string[] argv={};
            Main(argv);
        }
    }
开发者ID:ShiJess,项目名称:CompanyStudy,代码行数:54,代码来源:IrcBot.cs

示例5: Main

    static void Main(string[] args)
    {
        TcpClient socketForServer ;
        bool status = true ;
        try
        {
            socketForServer = new TcpClient("localhost",8100) ;
            Console.WriteLine("Connected to Server") ;

        }
        catch
        {
            Console.WriteLine("Failed to Connect to server{0}:8100","localhost") ;
            return ;
        }

        NetworkStream networkStream = socketForServer.GetStream() ;
        StreamReader streamreader = new StreamReader(networkStream) ;
        StreamWriter streamwriter = new StreamWriter(networkStream) ;

        try
        {
            string clientmessage="" ;
            string servermessage="" ;

            while(status)
            {

                Console.Write("Client:") ;
                clientmessage = Console.ReadLine() ;
                if((clientmessage=="bye") || (clientmessage=="BYE"))
                {
                    status = false ;
                    streamwriter.WriteLine("bye") ;
                    streamwriter.Flush() ;
                }
                if((clientmessage!="bye") && (clientmessage!="BYE"))
                {
                    streamwriter.WriteLine(clientmessage) ;
                    streamwriter.Flush() ;
                    servermessage = streamreader.ReadLine() ;
                    Console.WriteLine("Server:"+servermessage) ;
                }
            }
        }
        catch
        {
            Console.WriteLine("Exception reading from the server") ;
        }
        streamreader.Close() ;
        networkStream.Close() ;
        streamwriter.Close() ;
    }
开发者ID:ShiJess,项目名称:CompanyStudy,代码行数:53,代码来源:ChatClient.cs

示例6: Run

    public static void Run()
    {
        TcpListener server = new TcpListener(IPAddress.Loopback, 8181);
        server.Start();
        using (TcpClient client = server.AcceptTcpClient())
        using (NetworkStream clientStream = client.GetStream())
        using (StreamReader sr = new StreamReader(clientStream))
        using (StreamWriter sw = new StreamWriter(clientStream))
        {
            Console.WriteLine(sr.ReadLine());
            Console.WriteLine(sr.ReadLine());
            Console.WriteLine(sr.ReadLine());
            Console.WriteLine(sr.ReadLine());
            Console.WriteLine(sr.ReadLine());
            Console.WriteLine(sr.ReadLine());

            sw.WriteLine("HTTP/1.1 101 Web Socket Protocol Handshake");
            sw.WriteLine("Upgrade: WebSocket");
            sw.WriteLine("Connection: Upgrade");
            sw.WriteLine("WebSocket-Origin: http://localhost:8080");
            sw.WriteLine("WebSocket-Location: ws://localhost:8181/websession");
            sw.WriteLine("");

            sw.Flush();

            // Accept send
            while (true)
            {
                //  read type byte
                byte type = (byte)clientStream.ReadByte();
                if (type != 0x00) { Console.Error.WriteLine("Erro no protocolo: The type byte was not 0x00"); break; }
                byte[] sendData = new byte[1024];
                byte sendDataByte; int sendDataIdx = 0;
                while ((sendDataByte = (byte)clientStream.ReadByte()) != 0xFF)
                {
                    sendData[sendDataIdx++] = sendDataByte;
                }

                String text = System.Text.ASCIIEncoding.Default.GetString(sendData, 0, sendDataIdx);
                Console.WriteLine("LINE: " + text);

                // Write down message ECHO
                clientStream.WriteByte(0x00);
                sw.Write(text.ToUpper());
                sw.Flush();
                clientStream.WriteByte(0xFF);

            }

        }
        server.Stop();
    }
开发者ID:cguedes,项目名称:webSockets,代码行数:52,代码来源:WebSocketsGuedes.cs

示例7: Main

    public static void Main(String[] args)
    {
        EchoClient conversant=null;
         StreamWriter swriter=null;
         StreamReader sreader=null;
         try {
        //Host name comes from command line
        //If no host specified, local machine is host
        String host=args.Length==1?args[0]:"127.0.0.1";

        //Connect to Echo server
        conversant=new EchoClient(host);

        //Get the stream between server and client
        NetworkStream ns=conversant.GetStream();

        //Create a user-friendly StreamWriter
        swriter=new StreamWriter(ns);

        //Create a user-friendly StreamReader
        sreader=new StreamReader(ns);

        //Prompt user for message to send to server
        //Period "exit" tells server to end session
        String input;
        Console.Write("Enter screen name: ");

        while ((input=Console.ReadLine())!="exit") {
        //Send message to server
        swriter.WriteLine(input);
        swriter.Flush();

        //Get the Echo from the server
        String returndata=sreader.ReadLine();
        Console.WriteLine("Reply from "+host+": "+returndata);
        Console.Write("Enter text: \"exit\" to stop: ");
        }

        //Send final message and scram
        swriter.WriteLine(".");
        swriter.Flush();

         } catch (Exception e) {
        Console.WriteLine(e+" "+e.StackTrace);
         } finally {
        //Close the connection whether exception thrown or not
        if (swriter!=null) swriter.Close();
        if (sreader!=null) sreader.Close();
        if (conversant!=null) conversant.Close();
         }
    }
开发者ID:JessicaMaxey,项目名称:Networks,代码行数:51,代码来源:EchoClient.cs

示例8: DESEncrypt

 public static string DESEncrypt(string input)
 {
     byte[] bytes = Encoding.ASCII.GetBytes((string)ConfigurationSettings.AppSettings["CipherKeyProd"]);
     DESCryptoServiceProvider cryptoProvider = new DESCryptoServiceProvider();
     MemoryStream memoryStream = new MemoryStream();
     CryptoStream cryptoStream = new CryptoStream(memoryStream,
         cryptoProvider.CreateEncryptor(bytes, bytes), CryptoStreamMode.Write);
     StreamWriter writer = new StreamWriter(cryptoStream);
     writer.Write(input);
     writer.Flush();
     cryptoStream.FlushFinalBlock();
     writer.Flush();
     return Convert.ToBase64String(memoryStream.GetBuffer(), 0, (int)memoryStream.Length);
 }
开发者ID:protonate,项目名称:csharp_sample1,代码行数:14,代码来源:FFCrypto.cs

示例9: String2Object

    public object String2Object(string s)
    {
        if (string.IsNullOrEmpty(s)) return null;

        MemoryStream ms = new MemoryStream();
        StreamWriter sw = new StreamWriter(ms);

        sw.Write(s);
        sw.Flush();

        ms.Position = 0;

        byte[] data = sf.Deserialize(ms) as byte[];
        ms.Close();

        MemoryStream stream = new MemoryStream(data);
        stream.Position = 0;

        object o = bf.Deserialize(stream);

        sw.Close();
        stream.Close();

        return o;
    }
开发者ID:lakeli,项目名称:shizong,代码行数:25,代码来源:Searializer.cs

示例10: WriteFile

    static void WriteFile(List<string> strings, string filename)
    {
        try
        {
            StreamWriter writer = new StreamWriter(filename);
            using (writer)
            {
                foreach (var str in strings)
                {

                    writer.WriteLine(str);
                    writer.Flush();
                }
            }
        }
        catch (FileNotFoundException fe)
        {
            Console.WriteLine(fe.Message);
        }
        catch (ArgumentException ae)
        {
            Console.WriteLine(ae.Message);
        }
        catch (OutOfMemoryException ofm)
        {
            Console.WriteLine(ofm.Message);
        }
    }
开发者ID:purlantov,项目名称:telerik_academy,代码行数:28,代码来源:SortListOfStrings.cs

示例11: ReadWrite

 static void ReadWrite(string readFrom, string writeTo)
 {
     try
     {
         StreamReader reader = new StreamReader(readFrom);
         using (reader)
         {
             StreamWriter writer = new StreamWriter(writeTo);
             string line = reader.ReadLine();
             using (writer)
             {
                 int lineNum = 1;
                 while (line != null)
                 {
                     writer.WriteLine("Line {0}: {1}", lineNum, line);
                     writer.Flush();
                     lineNum++;
                     line = reader.ReadLine();
                 }
             }
         }
     }
     catch (ArgumentException ae)
     {
         Console.WriteLine(ae.Message);
     }
     catch (FileNotFoundException fe)
     {
         Console.WriteLine(fe.Message);
     }
 }
开发者ID:purlantov,项目名称:telerik_academy,代码行数:31,代码来源:InsertLineNumber.cs

示例12: Main

 public static void Main(String[] args)
 {
     TcpListener server = new TcpListener(int.Parse(args[0]));
     server.Start();
     TcpClient client = server.AcceptTcpClient();
     NetworkStream stream = client.GetStream();
     StreamReader reader = new StreamReader(stream);
     String s = reader.ReadLine();
     String[] strings = s.Split();
     StreamWriter writer;
     if (strings[0] != "GET") {
       writer = new StreamWriter(stream);
       writer.WriteLine
              ("HTTP/1.0 501 Not Implemented");
       writer.WriteLine();
     } else {
        String filename = strings[1];
        while(reader.ReadLine() != "");
        writer = new StreamWriter(stream);
        writer.WriteLine("HTTP/1.0 200 OK");
        writer.WriteLine("Content-type: text/plain");
        writer.WriteLine();
        StreamReader file = new StreamReader(filename);
        String z = file.ReadToEnd();
        writer.WriteLine(z);
        writer.Flush();
        writer.Close();
        file.Close();
     }
     client.Close();
     stream.Close();
     reader.Close();
     writer.Close();
     server.Stop();
 }
开发者ID:JnS-Software-LLC,项目名称:CSC153,代码行数:35,代码来源:VerySimpleWebServer.cs

示例13: Main

 static void Main()
 {
     Console.Write("n = ");
     int n = int.Parse(Console.ReadLine());
     Console.Write("Enter path to the file: ");
     StreamReader lines = new StreamReader(Console.ReadLine());
     int[,] matrix = new int[n, n];
     for (int i = 0; i < n; i++)
     {
         string line = lines.ReadLine();
         Console.WriteLine(line);
         var nums = line.Split(' ');
         for (int j = 0; j < n; j++)
         {
             matrix[i, j] = int.Parse(nums[j]);
         }
     }
     int max = matrix[0, 0] + matrix[0, 1] + matrix[1, 0] + matrix[1, 1];
     for (int i = 0; i < n-1; i++)
     {
         for (int j = 0; j < n-1; j++)
         {
             int sum = matrix[i, j] + matrix[i, j + 1] + matrix[i + 1, j] + matrix[i + 1, j + 1];
             if(sum > max)
             {
                 max = sum;
             }
         }
     }
     Console.Write("Enter path to the new fille: ");
     StreamWriter writer = new StreamWriter(Console.ReadLine());
     writer.Write(max);
     writer.Flush();
     Console.WriteLine("File is written!");
 }
开发者ID:PavDragneva,项目名称:TelerikAcademy,代码行数:35,代码来源:05.+Maximal+area+sum.cs

示例14: ErrorLog

 public void ErrorLog(string sPathName, string sErrMsg)
 {
     StreamWriter sw = new StreamWriter(sPathName + sErrorTime, true);
     sw.WriteLine(sLogFormat + sErrMsg);
     sw.Flush();
     sw.Close();
 }
开发者ID:mominbd,项目名称:testing,代码行数:7,代码来源:CreateLogFiles.cs

示例15: Conversation

    public void Conversation()
    {
        try {
        Console.WriteLine("Connection accepted.");

        //Make a user-friendly StreamReader from the stream
        sr=new StreamReader(client.GetStream());

        //Make a user-friendly StreamWriter from the stream
        sw=new StreamWriter(client.GetStream());

        String incoming=sr.ReadLine();
        while (incoming!=".") {
        Console.WriteLine("Message received: "+incoming);
        sw.WriteLine(incoming);
        sw.Flush();
        Console.WriteLine("Message Sent back: " + incoming);
        incoming=sr.ReadLine();
        }

        Console.WriteLine("Client sent '.': closing connection.");
        sr.Close();
        sw.Close();
        client.Close();
        } catch (Exception e) {
        Console.WriteLine(e+" "+e.StackTrace);
        } finally {
        if (sr!=null) sr.Close();
        if (sw!=null) sw.Close();
        if (client!=null) client.Close();
        }
    }
开发者ID:JessicaMaxey,项目名称:Networks,代码行数:32,代码来源:EchoServer.cs


注:本文中的StreamWriter.Flush方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。