如何上传使用相对路径文件 [英] How to upload file with relative path

查看:299
本文介绍了如何上传使用相对路径文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:结果
  <一href=\"http://stackoverflow.com/questions/5963535/java-lang-illegalargumentexception-contains-a-path-separator\">java.lang.IllegalArgumentException:包含路径分隔符

我想从我的SD卡,文件路径URL =SD卡/文件夹/ Test.doc的上传文件。我使用下面的code上传到服务器。

I am trying to upload a file from my sdcard, file path url="sdcard/Folder/test.doc". I am using the following code to upload to server.

String url = path.getText().toString();
FileInputStream fis = openFileInput(url);

这是给我的错误:

It is giving me error :

FATAL EXCEPTION: main 10-19 01:19:39.480: E/AndroidRuntime(7459): java.lang.IllegalArgumentException: File /sdcard/download/ABC.pdf contains a path separator.

能否有人请告诉我如何把它做?

Can some one please tell me how to get it done?

推荐答案

openFileInput(URL); 不能打开的文件存储在SD卡。此方法用于的打开这个背景下的应用程序包关联的私人文件进行读取。

openFileInput(url); can not open file stored on sdcard. this method is used to Open a private file associated with this Context's application package for reading.

您必须使用新建文件(路径)方法来创建或打开一个文件。然后用适当的InputStream。可以参考下面的语法。

you must use new File(path) method to create or open a file. then use appropriate InputStream. can refer below syntax..

File dir = Environment.getExternalStorageDirectory();
File yourFile = new File(dir, "path/to/the/file/inside/the/sdcard.ext");

这篇关于如何上传使用相对路径文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆