C# & JAVA:读写文件

using System;
using System.IO;
using System.Text; namespace ConsoleApplication4 {
class Program {
public static void Read(string path) {
FileStream fs = new FileStream(path, FileMode.Open);
StreamReader read = new StreamReader(fs, Encoding.Default);
string strReadline; int nLine = 1;
while ((strReadline = read.ReadLine()) != null)
{
Console.WriteLine((nLine++) + ":" + strReadline);
}
fs.Close();
read.Close();
} static void Main(string[] args) {
Read(@"D:\ExamData\西游记.txt");
}
}
}

  ↑C#

↓Java

import java.io.*;

public class ReadFile {
public static void Read(Stringpath) {
try {
FileInputStream fis = new FileInputStream(path);
InputStreamReader isr = new InputStreamReader(fis, "GBK");
BufferedReader br = new BufferedReader(isr);
String line = "";
int nLine = 1;
while ((line = br.readLine()) != null) {
System.out.println((nLine++) + ":" + line);
}
br.close();
isr.close();
fis.close();
} catch (IOExceptione) {
e.printStackTrace();
}
} publicstaticvoid main(String[] args) {
Read("D:/ExamData/西游记.txt");
}
}

  

上一篇:step2-------使用myeclipse创建maven java web项目


下一篇:Maven——eclipse中使用Maven创建Web项目