.net移植到java_需要将Visual Basic .NET代码移植到Java

Try

Dim sr As New IO.StreamReader(Mapfile & ".txt")

'Dim intValue As String = ""

Dim strLine As String = ""

Dim X As Integer = 0

Dim Y As Integer = 0

Do Until sr.EndOfStream

strLine = sr.ReadLine

strLine = strLine.Replace(strLine.LastIndexOf(","), "")

For Each item As String In Split(strLine, ",", -1)

'MsgBox("X:" & X & " Y:" & Y & "= " & item)

If item = "" Then

item = 0

End If

If X <= MapWidth Then

Map(X, Y, 0) = Int(item)

End If

X = X + 1

Next

X = 0

Y = Y + 1

Loop

sr.Close()

sr.Dispose()

Catch ex As Exception

MsgBox("Map: " & Mapfile & " could not be loaded." & vbCrLf & vbCrLf & ex.Message, MsgBoxStyle.Critical, "ERROR")

IsOn = False

End Try尝试将此代码从Visual Basic转移到Java。我试过使用Buffered Reader,但似乎没有做到这一点。上面的代码是针对Visual Basic的,下面的代码是我的java端口,看起来似乎没有相同的工作。 http://pastebin.com/freXYTi3

public void readFile(Context c) {

BufferedReader br = null;

try {

br = new BufferedReader(new InputStreamReader(c.getAssets().open("map1.txt")));

String line = null;

String newLine = "";

int x = 0;

int y = 0;

while ((line = br.readLine()) != null) {

int length = line.length();

String lastChar = line.substring(length-1);

if (lastChar.contains(",")) {

newLine = line.substring(0,length-1) + "";

}

//line = line.substring(0, line.lastIndexOf(",")) + "";

for (String str : line.split(",", -1)) {

System.out.println(str);

if(str == ""){

str = "0";

}

if(x <= mapwidth){

System.out.println(x + " " + y);

int N = Integer.parseInt(str);

Map[x][y] = N;

}

x = x + 1;

}

x = 0;

y = y + 1;

}

}

catch (FileNotFoundException ex) {

ex.printStackTrace();

}

catch (IOException ex) {

ex.printStackTrace();

}

finally {

try {

if (br != null)

br.close();

}

catch (IOException ex) {

ex.printStackTrace();

}

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值