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";}} }