我正在尝试使用不久前发布的方法将图像文件(jpeg)上传到我的测试服务器:
try {
String pathToOurFile = path;
FileInputStream fileInputStream =
new FileInputStream(new File(pathToOurFile) );
BufferedInputStream bis = new BufferedInputStream(fileInputStream,3000);
byte[] bt=new byte[bis.available()];
HttpURLConnection connection =
(HttpURLConnection)new URL(string).openConnection();
connection.setDoOutput(true);
connection.setRequestMethod("POST");
connection.connect();
FileOutputStream input = (FileOutputStream) connection.getOutputStream();
input.write(bt);
bis.close();
} catch (MalformedURLException e) {
Context context = null;
Toast.makeText(context, "error in writing", Toast.LENGTH_LONG).show();
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
我在这一行收到 ClassCastException: FileOutputStream input = (FileOutputStream) connection.getOutputStream(); 认为 Eclipse 不会将其标记为错误。我该如何解决?
PS 该项目是针对 API lvl 17 编译的