我试图在将文件上传到服务器之前重命名该文件....文件正在重命名,但它正在抛出fileNotFoundException
。请帮忙
HttpURLConnection conn;
DataOutputStream dos;
String lineEnd = "\r\n";
String twoHyphens = "--";
String boundary = "*****";
int bytesRead, bytesAvailable, bufferSize;
byte[] buffer;
int maxBufferSize = 1024 * 1024;
int maxSize = 1024 * 1024;
File sourceFile = new File(fileuri);
final String name = fileuri.substring(fileuri.lastIndexOf("/") + 1);
String directory = fileuri.replace(name, "");
File to = new File(directory, filename);
sourceFile.renameTo(to);
String path=sourceFile.getPath().toString();
final long length = sourceFile.length();
if (length / maxSize > 1) {
runOnUiThread(new Runnable() {
public void run() {
Toast.makeText(getApplicationContext(), "File Larger than 1MB", Toast.LENGTH_SHORT).show();
}
});
return 0;
}
if (!sourceFile.isFile()) {
Log.e("uploadFile", "Source File not exist :" + imagepath);
runOnUiThread(new Runnable() {
public void run() {
Toast.makeText(getApplicationContext(), "Source File not exist :", Toast.LENGTH_SHORT).show();
}
});
return 0;`