菜鸟求助 (100分)

  • 主题发起人 alexguang
  • 开始时间
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 "";
}
......
......
......
}
 
5555555555,都没有人理我。[:(!][:(!][:(!][:(!]
 
outputstream.write() 怎么能这样写呢?
试试
...
OutputStream outputstream = urlconnection.getOutputStream();
BufferedOutputStream bos = new BufferedOutputStream(outputstream);
bos.write(abyte0, 0, abyte0.length);
bos.flush();
 
outputstream.write()可以那样写的,谢谢你哈,现在我已经测试成功,100分送给你啦,呼呼~~
 
接受答案了.
 
顶部