public void run()
{
BufferedReader br = null;
ss = new ServerSocket(9999);
_L2:
long filelength;
int result;
s = ss.accept();
br = new BufferedReader(new InputStreamReader(s.getInputStream()));
String fileName = br.readLine();
filelength = Long.parseLong(br.readLine());
String IP = s.getInetAddress().toString();
String message = (new StringBuilder("\u662F\u5426\u63A5\u6536\u6765\u81EA")).append(IP).append("\u5927\u5C0F\u4E3A").append(filelength).append("\u7684").append(fileName).append("?").toString();
result = JOptionPane.showConfirmDialog(null, message);
if(result == 1)
{
try
{
if(br != null)
br.close();
}
catch(IOException e)
{
e.printStackTrace();
}
return;
}
if(result != 0) goto _L2; else goto _L1
_L1:
(new Thread(new ReceiveThread(s, c, filelength))).start();
goto _L2
IOException e;
e;
e.printStackTrace();
try
{
if(br != null)
br.close();
}
catch(IOException e)
{
e.printStackTrace();
}
break MISSING_BLOCK_LABEL_232;
Exception exception;
exception;
try
{
if(br != null)
br.close();
}
catch(IOException e)
{
e.printStackTrace();
}
throw exception;
}反编译后的结果,可以帮我把正确的代码写出来吗,我不懂~~
long filelength;
int result;
Socket s = ss.accept();
br = new BufferedReader(new InputStreamReader(s.getInputStream()));
String fileName = br.readLine();
filelength = Long.parseLong(br.readLine());
String IP = s.getInetAddress().toString();
String message = (new StringBuilder("\u662F\u5426\u63A5\u6536\u6765\u81EA")).append(IP).append("\u5927\u5C0F\u4E3A").append(filelength).append("\u7684").append(fileName).append("?").toString();
result = JOptionPane.showConfirmDialog(null, message);
if(result == 1)
{
try
{
if(br != null)
br.close();
}
catch(IOException e)
{
e.printStackTrace();
}
return;
}
if(result == 0)
{
(new Thread(new ReceiveThread(s, c, filelength))).start();
}
}
while(true);
把关键字goto都编译出来了
public void run()
{
BufferedReader br = null;
try
{
ss = new ServerSocket(9999);
for(;;)
{
long filelength;
int result;
s = ss.accept();
br = new BufferedReader(new InputStreamReader(s.getInputStream()));
String fileName = br.readLine();
filelength = Long.parseLong(br.readLine());
String IP = s.getInetAddress().toString();
String message = "是否接收来自"+IP +"大小为"+filelength+"的"+fileName+"?";
result = JOptionPane.showConfirmDialog(null, message);
if(result == 1)
{
try
{
if(br != null)
br.close();
}
catch(IOException e)
{
e.printStackTrace();
}
return;
}
if(result == 0)
break;
new Thread(new ReceiveThread(s, c, filelength)).start();
}
}
catch(IOException e)
{
e.printStackTrace();
}
finally
{
try
{
if(br != null)
br.close();
}
catch(IOException e)
{
e.printStackTrace();
}
}
}
总的来说这段代码的逻辑肯定是有问题的。
BuferedReader br的用法不对,基本上不能在当前的连接上接收文件。
Swing程序根本就不能这么写。这代码够烂的了。
public void run()
{
BufferedInputStream bis;
BufferedOutputStream bos;
byte b[];
JFileChooser fc = new JFileChooser();
int rt = fc.showSaveDialog(null);
fc.setFileSelectionMode(1);
if(rt != 0)
break MISSING_BLOCK_LABEL_369; ///为什么会有这行的~? filepath = fc.getSelectedFile();
bis = null;
bos = null;
b = new byte[0x20000];
int num = 0;
try
{
bis = new BufferedInputStream(sReceive.getInputStream());
bos = new BufferedOutputStream(new FileOutputStream(filepath));
long receiveData = 0L;
long preTime = (new Date()).getTime();
long curTime = preTime;
long amount = 0L;
int num;
while((num = bis.read(b)) != -1)
{
bos.write(b, 0, num);
receiveData += num;
amount += num;
curTime = (new Date()).getTime();
pb.setValue((int)((receiveData / filelength) * 100L));
if(curTime - preTime > 500L)
{
lSendRate.setText((new StringBuilder("\u4F20\u8F93\u901F\u7387\u4E3A")).append(getFilelength((amount * 1000L) / (curTime - preTime))).append("/\u79D2").toString());
preTime = curTime;
amount = 0L;
}
}
lShowSendMessage.setText("\u6587\u4EF6\u63A5\u53D7\u5B8C\u6BD5");
break MISSING_BLOCK_LABEL_334;
}
catch(IOException e)
{
e.printStackTrace();
}
try
{
if(bis != null)
bis.close();
if(bos != null)
bos.close();
sReceive.close();
}
catch(IOException e)
{
e.printStackTrace();
}
break MISSING_BLOCK_LABEL_369;
Exception exception;
exception;
try
{
if(bis != null)
bis.close();
if(bos != null)
bos.close();
sReceive.close();
}
catch(IOException e)
{
e.printStackTrace();
}
throw exception;
try
{
if(bis != null)
bis.close();
if(bos != null)
bos.close();
sReceive.close();
}
catch(IOException e)
{
e.printStackTrace();
}
}异常怎么弄~?
各位高手,可以帮我解决上面的问题吗~?谢谢啦