java上传前重命名文件

时间:2013-02-06 09:05:44

标签: java android

我遇到了问题,我有这样的源代码

public int uploadFile(String sourceFileUri) {
     SharedPreferences myPref = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    String upLoadServerUri = new String(myPref.getString("serverURL", Constants.URL)+"/upload.php");
    String fileName = picturePath;

    HttpURLConnection conn = null;
    DataOutputStream dos = null;  
    String lineEnd = "\r\n";
    String twoHyphens = "--";
    String boundary = "*****";
    int bytesRead, bytesAvailable, bufferSize;
    byte[] buffer;
    int maxBufferSize = 1 * 1024 * 1024; 
    File sourceFile = new File(picturePath);

如何在上传之前重命名 picturePath 上的文件。 谢谢

1 个答案:

答案 0 :(得分:0)

你可以尝试把它放在函数的乞讨中:

File renamed =new File(sourceFileUri);
renamed.renameTo(new File("newfile.png"));

然后你将调用renamed.getAbsolutePath();而不是sourceFileUri。

相关问题