我知道我们应该在我们的问题中添加一些代码,但我真的很傻眼,不能包裹我的头脑或找到任何可以遵循的例子.
基本上我想打开文件C:\ A.txt,其中已有内容,并在结尾处写一个字符串.基本上是这样的.
文件A.txt包含:
John
Bob
Larry
Run Code Online (Sandbox Code Playgroud)
我想打开它并在结尾写Sue所以文件现在包含:
John
Bob
Larry
Sue
Run Code Online (Sandbox Code Playgroud)
很抱歉没有代码示例,今天早上我的大脑已经死了......
我正在尝试使用Microsoft Word和PDF查看器从我的应用程序中的文件加载文档,我正在使用FileProvider处理Android 7.0+,不允许文件URI自由传递.我得到了这样的URI并设置了Intent标志以允许在打开之前进行读写,如下所示:
// From the byte array create a file containing that data, and get extension and MIME type.
File fileToOpen = byteArrayToFile(documentData, shortFileName);
String fileExtension = UtilityMethods.getFileExtension(fileToOpen.getName());
String mime = MimeTypeMap.getSingleton().getMimeTypeFromExtension(fileExtension);
// Get the Uri for the file from the file provider, open using intent.
Uri documentUri = FileProvider.getUriForFile(getContext(), "com.mycompany.provider", fileToOpen);
Intent intent = new Intent();
intent.setDataAndType(documentUri, mime);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
intent.setAction(Intent.ACTION_VIEW);
startActivity(intent);
Run Code Online (Sandbox Code Playgroud)
但是,当文件在MS Word中加载时,该文件是只读的,并且无法编辑,这不是所需的行为.我哪里错了?