ReadLine and while problems in C # and JAVA __java

Source: Internet
Author: User
Tags readline

I have a text file that I want to take one line at a time.

In C #, the first while loop starts with the first line, while in Java it starts with the second row.

I just experimented, the specific reason is still not clear, but also hope that the insider came out to explain. Thank you.

The code is as follows:

Using System; Using System.IO; Using System.Collections.Generic; Using System.ComponentModel; Using System.Data; Using System.Drawing; Using System.Linq; Using System.Text; Using System.Windows.Forms; namespace WindowsFormsApplication1 {public partial class Form1:form {public Form1 () {InitializeComponent ();} private void Button1_Click (object sender, EventArgs e) {try {StreamReader reader = new StreamReader (@ "D:/javawork/mb.hua", Syst Em. Text.Encoding.Default); string input = TextBox1.Text; String line = reader. ReadLine (); while (line!= null) {if (Line.startswith (input)) {MessageBox.Show (line.substring (1, 4));} line = reader. ReadLine (); } catch (Exception E1) {MessageBox.Show ("error, feedback question, visit http://anforen.5d6d.com");} } }

The above is C # version.

The following is a Java version:

Package Fourcorner.server import java.io.*; import fourcorner.client.GreetingService; import Com.google.gwt.user.server.rpc.RemoteServiceServlet; /** * The server side implementation of the RPC service. */@SuppressWarnings ("Serial") public class Greetingserviceimpl extends Remoteserviceservlet implements Greetingservice {public string Greetserver (string input) {try{FileReader fr=new filereader ("Web-inf/mb.hua"); BufferedReader br=new BufferedReader (FR); String Line=br.readline (); while (Line!=null) {if (Line.startswith (input)) {return line.substring (1, 5);} Line=br.readline (); if (line==null) return "Please enter a Chinese character, feedback questions please visit http://anforen.5d6d.com"; Br.close (); Fr.close (); return line.tostring (); The catch (Exception e) {return "error occurs, please visit http://anforen.5d6d.com";}} }  

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.