A
alexguang
Unregistered / Unconfirmed
GUEST, unregistred user!
[]请大家看看下面的代码,在执行到红字的时候总是执行异常的部分(即执行篮字的部分),所以if语句总是执行绿字的部分,这是为什么呢?save.php文件内容是随便写的,是不是save.php的内容有要求啊?为什么他不执行try里面的内容呢?
public class baocunshezhi extends Panel
implements ItemListener
{
...
...
...
public void b(String s)
{
....
....
....
try
{
URL url = new URL("http://localhost/save.php");
URLConnection urlconnection = url.openConnection();
StringBuffer stringbuffer = new StringBuffer();
urlconnection.setDoInput(true);
urlconnection.setDoOutput(true);
stringbuffer.append(URLEncoder.encode("filename"));
stringbuffer.append('=');
stringbuffer.append(URLEncoder.encode(s));
String s4 = stringbuffer.toString();
int i2 = s4.length();
byte abyte0[] = s4.getBytes();
urlconnection.setRequestProperty("Request-method", "post");
urlconnection.setRequestProperty("Content-length", Integer.toString(i2));
urlconnection.setRequestProperty("Content-type", "application/x-www-form-urlencoded");
OutputStream outputstream = urlconnection.getOutputStream();
[red] outputstream.write(abyte0);
[/red]
outputstream.flush();
String s5 = a(urlconnection);
if(s5 != null)
{
[green] f.b("保存文件失败");
c = false;
[/green] } else
{
f.b("已成功保存文件");
c = true;
b();
}
}
catch(Exception exception)
{
f.b("无法保存文件");
exception.printStackTrace();
}
}
public String a(URLConnection urlconnection)
{
try
{
InputStreamReader inputstreamreader = new InputStreamReader(urlconnection.getInputStream());
BufferedReader bufferedreader = new BufferedReader(inputstreamreader);
String s = bufferedreader.readLine();
System.out.println("The result line is: " + s);
return s;
}
catch(EOFException eofexception)
{
eofexception.printStackTrace();
return "发生异常!";
}
[blue]catch(Exception exception)
{
exception.printStackTrace();
} [/blue] return "";
}
......
......
......
}
public class baocunshezhi extends Panel
implements ItemListener
{
...
...
...
public void b(String s)
{
....
....
....
try
{
URL url = new URL("http://localhost/save.php");
URLConnection urlconnection = url.openConnection();
StringBuffer stringbuffer = new StringBuffer();
urlconnection.setDoInput(true);
urlconnection.setDoOutput(true);
stringbuffer.append(URLEncoder.encode("filename"));
stringbuffer.append('=');
stringbuffer.append(URLEncoder.encode(s));
String s4 = stringbuffer.toString();
int i2 = s4.length();
byte abyte0[] = s4.getBytes();
urlconnection.setRequestProperty("Request-method", "post");
urlconnection.setRequestProperty("Content-length", Integer.toString(i2));
urlconnection.setRequestProperty("Content-type", "application/x-www-form-urlencoded");
OutputStream outputstream = urlconnection.getOutputStream();
[red] outputstream.write(abyte0);
[/red]
outputstream.flush();
String s5 = a(urlconnection);
if(s5 != null)
{
[green] f.b("保存文件失败");
c = false;
[/green] } else
{
f.b("已成功保存文件");
c = true;
b();
}
}
catch(Exception exception)
{
f.b("无法保存文件");
exception.printStackTrace();
}
}
public String a(URLConnection urlconnection)
{
try
{
InputStreamReader inputstreamreader = new InputStreamReader(urlconnection.getInputStream());
BufferedReader bufferedreader = new BufferedReader(inputstreamreader);
String s = bufferedreader.readLine();
System.out.println("The result line is: " + s);
return s;
}
catch(EOFException eofexception)
{
eofexception.printStackTrace();
return "发生异常!";
}
[blue]catch(Exception exception)
{
exception.printStackTrace();
} [/blue] return "";
}
......
......
......
}