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需要將Visual Basic .NET代碼移植到Java
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();
}
}
}
」似乎沒有任何東西給我想要我想要的東西「幾乎不是一個什麼問題的詳細描述。請閱讀http://tinyurl.com/so-hints – 2012-03-02 23:40:33
爲什麼不發佈您的Java轉換的粗略版本,我們可以幫助您糾正它。 – 2012-03-02 23:41:06
我可以發表我寫的代碼。堅持在 – Xwire 2012-03-02 23:41:27