fileinputstream

is possible to convert FileOutputStream to byte array?

China☆狼群 提交于 2020-01-01 19:21:34
问题 I want to convert FileOutputStream to Byte array for passing binary data between two applications. please any one can help? 回答1: To convert a file to byte array, ByteArrayOutputStream class is used. This class implements an output stream in which the data is written into a byte array. The buffer automatically grows as data is written to it. The data can be retrieved using toByteArray() and toString(). To convert byte array back to the original file, FileOutputStream class is used. A file

Modifying FileInputStream for mediaPlayer setDataSource

拜拜、爱过 提交于 2019-12-29 01:44:09
问题 I'm trying to modify (extend) the FileInputStream class so that I can open an encrypted file and use the stream for MediaPlayer's setDataSource(FileDescriptor) . Problem is I don't know which method should be overridden to do the decryption inside the stream. I tried overriding all the read() methods, but the mediaPlayer doesn't seem to use them. Any suggestions? 回答1: I don't think that MediaPlayer accepts any kind of InputStream. You can't modify data read from file that are used in

Invalidate Stream without Closing

巧了我就是萌 提交于 2019-12-24 00:03:27
问题 This is a followup to anonymous file streams reusing descriptors As per my previous question, I can't depend on code like this (happens to work in JDK8, for now): RandomAccessFile r = new RandomAccessFile(...); FileInputStream f_1 = new FileInputStream(r.getFD()); // some io, not shown f_1 = null; f_2 = new FileInputStream(r.getFD()); // some io, not shown f_2 = null; f_3 = new FileInputStream(r.getFD()); // some io, not shown f_3 = null; However, to prevent accidental errors and as a form of

Getting wrong bytes from Java compared to C#

我是研究僧i 提交于 2019-12-22 11:35:13
问题 So I have some FRX binary files from which I am attempting to get string captions using Java's binary reading methods. I was capable of doing so, and specifying the region in which to read bytes in C# using the following program : using System; using System.Collections.Generic; using System.Text; using System.IO; public class GetFromFRX { public static void Main() { StringBuilder buffer = new StringBuilder(); using (BinaryReader b = new BinaryReader(File.Open("frmResidency.frx", FileMode.Open

Java read object input stream into arraylist?

断了今生、忘了曾经 提交于 2019-12-22 05:19:06
问题 The method below is supposed to read a binary file into an arrayList . But getting a java.io.EOFException : at java.io.ObjectInputStream$BlockDataInputStream.peekByte(ObjectInputStream.java:2553) at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1296) at java.io.ObjectInputStream.readObject(ObjectInputStream.java:350) at .... Read(Tester.java:400) at .... main(Tester.java:23) Line 23 at main just calls the method, line 400 is the while loop below. Any ideas? private static void

File not found exception (Path from URI)

Deadly 提交于 2019-12-22 04:45:22
问题 I'm trying to get a FileInputStream object for the picture a user selects from their gallery and when I'm trying to open the file from the URI I receive, it keeps saying FileNotFoundException ... Here's the code I'm using to fire off the intent for picking an image from the gallery: Intent intent = new Intent(); intent.setType("image/*"); intent.setAction(Intent.ACTION_GET_CONTENT); startActivityForResult(Intent.createChooser(intent, "Select Picture"), PICK_IMAGE_REQUEST); And here's the code

How can I access a txt file in a jar with FileInputStream?

≡放荡痞女 提交于 2019-12-21 12:51:08
问题 I am aware of the getResourceAsStream() method but there is an issue with the parser that reads the file, the whole structure was implemented to expect a FileInputStream() and the getResourceAsStream() returns an input stream which cannot be casted. Is there any easy "fix" for this situation? 回答1: A resource contained within a JAR file is not itself a file, and cannot be read using a FileInputStream . If you have code that absolutely requires a FileInputStream , then you'll need to extract

FileChannel returns wrong file size of file in assets folder

十年热恋 提交于 2019-12-21 05:18:25
问题 I am trying to read a File from the raw folder in my assets using a FileInputStream . This is how I create the FileInputStream : AssetManager assetManager = getAssets(); AssetFileDescriptor fileDescriptor = assetManager.openFd(fileName); FileInputStream inputStream = new FileInputStream(fileDescriptor.getFileDescriptor()); After that I am trying to read the data from the File like this: FileChannel fileChannel = inputStream.getChannel(); MappedByteBuffer mappedByteBuffer = fileChannel.map

Different behavior of XmlPullParser.getInputEncoding() on API11+ and pre-API11 versions of Android

你说的曾经没有我的故事 提交于 2019-12-19 11:17:58
问题 I am developing a new feature for my android app to enable data backup and restore. I am using XML files to backup data. This is a piece of code that sets encoding for an output file: XmlSerializer serializer = Xml.newSerializer(); FileWriter fileWriter = new FileWriter(file, false); serializer.setOutput(fileWriter); serializer.startDocument("UTF-8", true); [... Write data to the file....] This is how I try to import data from an XML file. First, I check if the encoding is correct:

Different behavior of XmlPullParser.getInputEncoding() on API11+ and pre-API11 versions of Android

我的未来我决定 提交于 2019-12-19 11:17:30
问题 I am developing a new feature for my android app to enable data backup and restore. I am using XML files to backup data. This is a piece of code that sets encoding for an output file: XmlSerializer serializer = Xml.newSerializer(); FileWriter fileWriter = new FileWriter(file, false); serializer.setOutput(fileWriter); serializer.startDocument("UTF-8", true); [... Write data to the file....] This is how I try to import data from an XML file. First, I check if the encoding is correct: