这段代码有什么问题,它给出了错误

时间:2013-08-23 07:56:53

标签: android upload

任何人都可以告诉我这个代码有什么问题它会返回语法错误的错误。任何人都可以解决它?

dos.writeBytes(twoHyphens + boundary + lineEnd); 
dos.writeBytes("Content-Disposition: form-data; name="uploaded_file";filename=""
+ fileName + """ + lineEnd);'

它的第二部分捕捉它返回错误。请检查一下:

runOnUiThread(new Runnable() {
public void run() {
String msg = "File Upload Completed.\n\n See uploaded file here : \n\n"
             +http://www.androidexample.com/media/uploads/"
             +uploadFileName;
messageText.setText(msg);
Toast.makeText(UploadToServer.this, "File Upload Complete.",Toast.LENGTH_SHORT).show();
      }
    });                
  }    
fileInputStream.close();
dos.flush();
dos.close();
} catch (MalformedURLException ex) {
  dialog.dismiss();  
  ex.printStackTrace();
runOnUiThread(new Runnable() {
 public void run() {
 messageText.setText("MalformedURLException Exception : check script url.");
 Toast.makeText(UploadToServer.this, "MalformedURLException",Toast.LENGTH_SHORT).show();

 }
 });
 Log.e("Upload file to server", "error: " + ex.getMessage(), ex);  
 } catch (Exception e) {
 dialog.dismiss();  
 e.printStackTrace();
 runOnUiThread(new Runnable() {
 public void run() {
  messageText.setText("Got Exception : see logcat ");
  Toast.makeText(UploadToServer.this, "Got Exception : see logcat ",Toast.LENGTH_SHORT).show();
  }});
 Log.e("Upload file to server Exception", "Exception : " + e.getMessage(), e);  
  }
  dialog.dismiss();       
  return serverResponseCode;              
 } // End else block
} 
}
 @Override
 public boolean onCreateOptionsMenu(Menu menu) {
 getMenuInflater().inflate(R.menu.upload_to_server, menu);
 return true;
 }
}

1 个答案:

答案 0 :(得分:0)

 dos.writeBytes("Content-Disposition: form-data; name=\"uploaded_file\";\"filename=\""+ fileName + "\"" + lineEnd);

双引号内不使用双引号,需要输入“\”(反斜杠)