what is wrong with this code it gives error

安稳与你 提交于 2019-12-19 12:52:23

问题


can anyone tell me that what is wrong with this code it returns the error of syntax error. can anyone fix it ?

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

and its second part at catch it returns error. check this one please:

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:


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

double qoutes are not used within double qoutes, you need to put "\" (backslash)



来源:https://stackoverflow.com/questions/18397670/what-is-wrong-with-this-code-it-gives-error

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!