fileoutputstream

Camera not saving image and drops exception

岁酱吖の 提交于 2019-12-02 01:33:25
I'm creating camera app. I'm doing that in fragment. I have FrameLayout where I add the camera, and one button for capture. There are 2 problems. Camera not saves the image. When I click second time on capture image, drops exception java.lang.RuntimeException: takePicture failed I don't know where's the problem, I'm using camera API first time. Camera I'm using only in portrait mode. And in manifests I added the permissions for camera and write external storage. I have one class where I'm extending SurfaceView . Let me show you the code. public class ShowCamera extends SurfaceView implements

java.io.StreamCorruptedException: Wrong format when reading more than 1 object [duplicate]

三世轮回 提交于 2019-12-01 23:08:08
问题 This question already has an answer here : StreamCorruptedException: invalid type code: AC (1 answer) Closed 2 years ago . I am trying to add an object( of OneChatMessage class) into a file on every button click. And then i try to read all the objects from the file and load it into a ArrayList . But i get a StreamCorruptedException at the second iteration of ObjectInputStream.readObject() in the deserialization function. I have verified that the first iteration works fine. I have read many

FileOutputStream opens a new file and deletes the contents whenever it is created

a 夏天 提交于 2019-12-01 22:57:45
问题 I'm dealing with serialization and deserialization in files. Moreover, i'm stack about using FileOutputStream with ObjectOutputStream . The issue is i have server/client chat application and whenever a client is connected, server must check that if connected client has registered before. So, when a client is connected to server, server creates an output stream like FileOutputStream fos = new FileOutputStream("src\\example\\mainList.txt"); to get a linkedlist to check whether this list

java.io.StreamCorruptedException: Wrong format when reading more than 1 object [duplicate]

末鹿安然 提交于 2019-12-01 21:02:53
This question already has an answer here: StreamCorruptedException: invalid type code: AC 1 answer I am trying to add an object( of OneChatMessage class) into a file on every button click. And then i try to read all the objects from the file and load it into a ArrayList . But i get a StreamCorruptedException at the second iteration of ObjectInputStream.readObject() in the deserialization function. I have verified that the first iteration works fine. I have read many other posts on the same issue : One suggestion( Deserialize multiple Java Objects ) is to write the entire array list to the file

Close a file created with FileOutputStream, for a next delete

五迷三道 提交于 2019-12-01 17:24:20
I am currently facing some problem with a FileOutputStream in my Java code. Actually I am using a FileOutputStream for creating a file, but then once the file is created there is no way for deleting it. As far as I could understand, this may come from the fact that the FileOutputstream is not closed. On below my summarized code : outFile = new FileOutputStream(dir+"\\"+fileName); outFile.write("Test"); outFile.flush(); outFile.close(); outFile = null; System.gc(); Then there is no way to delete the file, even "by hand". When my program is launched, I can't delete it on windows by a simple del.

How to decode base64 string and convert it into pdf/jpg and save it in storage

混江龙づ霸主 提交于 2019-12-01 15:10:10
问题 I would like to decode a base64 string and turn it into a file (as pdf/jpg) and save it to device, how for example in (/storage/emulated/0/Download/file.pdf). For encode a file i use this code: File originalFile = new File("/mnt/sdcard/download/file.pdf"); String encodedBase64 = null; try { FileInputStream fileInputStreamReader = new FileInputStream(originalFile); byte[] bytes = new byte[(int) originalFile.length()]; fileInputStreamReader.read(bytes); encodedBase64=Base64.encodeToString(bytes

aws s3 java sdk download pdf getting corrupted

亡梦爱人 提交于 2019-12-01 10:40:45
I am downloading files from aws s3 using the getObject api. Simple text files work fine, but on pdf download my file is corrupted. I am using FileOutputStream and saving contents in a file, but the pdf saved is getting corrupted. I am not quite sure about the correct java api to use for this purpose and what should be the size of the byte array where the bytes read get written. I am also curious if using the SDK directly makes sense, or is there are open source wrapper api's available in Java that I could be leveraging. FileOutputStream fout = new FileOutputStream(new File(destFileName)); byte

Creating and writing file from a FileOutputStream in Java

回眸只為那壹抹淺笑 提交于 2019-12-01 10:16:02
问题 Okay, so I'm working on a project where I use a Java program to initiate a socket connection between two classes (a FileSender and FileReceiver ). My basic idea was that the FileSender would look like this: try { writer = new DataOutputStream(connect.getOutputStream()); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } //While we have bytes to send while(filein.available() >0){ //We write them out to our buffer writer.write(filein.read(outBuffer)); writer

Android: Write text to txt

依然范特西╮ 提交于 2019-12-01 06:29:16
With the following code, I try to write to my sdcard: public void writedata(String data) { //BufferedWriter out = null; System.out.println(data); try{ FileOutputStream out = new FileOutputStream(new File("/sdcard/tsxt.txt")); out.write(data.getBytes()); out.close(); } catch (Exception e) { //fehlende Permission oder sd an pc gemountet} System.out.println("CCCCCCCCCCCCCCCCCCCCCCCALSKDJLAK"); } } The permission in the Manifest: <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> But now, when I open the file, nothing is in there. Where´s the problem? I´m sure data has

OutputStreamWriter does not append

孤者浪人 提交于 2019-12-01 03:55:01
Original code and its working saving the data to the SD Card // Writing data to internal storage btnSaveData.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (isSDCardWritable()) { String dataToSave = etData.getText().toString(); try { // SD Card Storage File sdCard = Environment.getExternalStorageDirectory(); File directory = new File(sdCard.getAbsolutePath()+"/MyFiles"); directory.mkdirs(); File file = new File(directory, "text.txt"); FileOutputStream fos = new FileOutputStream(file); OutputStreamWriter osw = new OutputStreamWriter(fos); // write the