How to reference a File in raw folder in Android

后端 未结 4 1212
陌清茗
陌清茗 2020-12-03 08:37

I just want to create a File object like this

File myImageFile = new File (\"image1\") ;

but it is giving me exception of FileNotFou

4条回答
  •  猫巷女王i
    2020-12-03 09:06

    You can use InputStreamBody instead of FileBody so you can use it like this:

    InputStream inputStream = resources.openRawResource(R.raw.yourresource);
    
    MultipartEntity multipartEntity= new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
    multipartEntity.addPart("uploaded", new InputStreamBody(inputStream));
    

提交回复
热议问题