gpt4 book ai didi

java - 使用 java 将整个文件夹上传到服务器(如果存在)

转载 作者:行者123 更新时间:2023-12-01 04:23:51 24 4
gpt4 key购买 nike

我是 java 新手,我需要完成这个应用程序并通过 Post 将整个文件夹发送到我的服务器。

现在代码可以运行,但我需要检查特定的文件夹名称和路径是否存在,然后使用线程上传功能发送所有文件。

引用的代码:

public class UploadToServer extends Activity {

TextView messageText;
Button uploadButton;
int serverResponseCode = 0;
ProgressDialog dialog = null;

String upLoadServerUri = null;

/********** File Path *************/
final String uploadFilePath = "/mnt/sdcard/folder/";
final String uploadFileName = "sample.jpg";

@Override
public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
setContentView(R.layout.activity_upload_to_server);

uploadButton = (Button)findViewById(R.id.uploadButton);
messageText = (TextView)findViewById(R.id.messageText);

messageText.setText("Uploading file path :- " + uploadFilePath + uploadFileName);

/************* Php script path ****************/
upLoadServerUri = "http://www.tutomax.com/uploads/Receiver.php";

uploadButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {

dialog = ProgressDialog.show(UploadToServer.this, "", "Uploading file...", true);

new Thread(new Runnable() {
public void run() {
runOnUiThread(new Runnable() {
public void run() {
messageText.setText("uploading started.....");
}
});

uploadFile(uploadFilePath + "" + uploadFileName);

}
}).start();
}
});
}

public int uploadFile(String sourceFileUri) {

....剩余代码上传功能

最佳答案

如何遍历指定文件夹下的所有文件,然后将匹配的文件一一上传。

关于java - 使用 java 将整个文件夹上传到服务器(如果存在),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18679465/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com