FileOutputStream异常EACCES权限被拒绝

时间:2016-06-20 13:14:50

标签: android permissions fileoutputstream storage-access-framework

我在论坛中尝试了很多解决方案,但它们似乎没有用。我需要在手机中创建一个pdf(Environment.getExternalStorageState()+ File.separator +&#34;尝试&#34; + File.separator +&#34; FirstPdf.pdf&#34 ;;)但我有一个例外。 我在清单中使用verifyStoragePermissions(this) <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

2 个答案:

答案 0 :(得分:0)

Environment.getExternalStorageState()替换为Environment.getExternalStorageDirectory()

答案 1 :(得分:0)

试试这个

@Configuration
@ComponentScan("abc")
public class Config {

    @Bean
    public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
        return new PropertySourcesPlaceholderConfigurer();
    }
}

注意:

你正在尝试public class Runner { public static void main(String[] args) { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Config.class); Test bean = context.getBean(Test.class); System.out.println(bean.javaPath); } } ,它会  File file = new File(Environment.getExternalStorageDirectory() +File.separator +"Try" +File.separator +"FirstPdf.pdf");\ // here your logic for write pdf file

参考: External storage state