Questions tagged [fileoutputstream]

FileOutputStream is a Java class used to write bytes directly to a File or to a FileDescriptor.

FileOutputStream is a Java class used to write bytes directly to a File or to a FileDescriptor.

Whether or not a file is available or may be created depends upon the underlying platform. Some platforms, in particular, allow a file to be opened for writing by only one FileOutputStream (or other file-writing object) at a time. In such situations the constructors in this class will fail if the file involved is already open.

FileOutputStream is meant for writing streams of raw bytes such as image data. For writing streams of characters, consider using FileWriter.

1128 questions
16
votes
5 answers

Java - how to efficiently write a sequential file with occassional holes in it

I have a requirement to write records to a file where the data is written at a file location (i.e, seek position) depending on the value of a numeric key. For example, if the key is 100, I might write at position 400. The records consist of the…
rghome
  • 8,529
  • 8
  • 43
  • 62
16
votes
2 answers

Android FileOutputStream location save file

I have an app that saves into a file (internal storage) data input by the user and at startup it loads this file and shows the contents. I would like to know: where can I find my file (data.txt)? In addition, if I input "Hello" and then "World" when…
xXJohnRamboXx
  • 739
  • 3
  • 10
  • 24
16
votes
4 answers

How do I write to a YAML file using SnakeYaml?

Consider the following code: public static void dumpObjectToYaml(String key, Object O, String path) throws IOException { Map data = new HashMap<>(); data.put(key, O); File F = new File(path); F.mkdirs(); …
Jonas Bartkowski
  • 357
  • 1
  • 6
  • 15
15
votes
1 answer

How to create a ZIP InputStream in Android without creating a ZIP file first?

I use NanoHTTPD as web server in my Android APP, I hope to compress some files and create a InputStream in server side, and I download the InputStream in client side using Code A. I have read Code B at How to zip and unzip the files?, but how to…
HelloCW
  • 843
  • 22
  • 125
  • 310
13
votes
2 answers

ext4/fsync situation unclear in Android (Java)

Tim Bray's article "Saving Data Safely" left me with open questions. Today, it's over a month old and I haven't seen any follow-up on it, so I decided to address the topic here. One point of the article is that FileDescriptor.sync() should be called…
Markus Junginger
  • 6,950
  • 31
  • 52
13
votes
5 answers

Deleting files created with FileOutputStream

I'm developing for the Android platform. My app creates a temp file with a simple call to: FileOutputStream fos = openFileOutput("MY_TEMP.TXT", Mode); It works fine because I can write to it and read it normally. The problem is that when I exit…
user396933
12
votes
2 answers

How to write a potentially huge InputStream to File?

I have an API call that returns a byte array. I currently stream the result into a byte array then make sure the checksums match and then write the ByteArrayOutputStream to File. The code is something like this and it works pretty well. String…
JoeLallouz
  • 1,338
  • 1
  • 10
  • 14
12
votes
2 answers

How to decode base64 string and convert it into PDF/JPG and save it in storage

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…
Edoardo Goffredo
  • 303
  • 2
  • 5
  • 20
12
votes
7 answers

FileOutputStream access is denied : JAVA

I have the following code with the iText library properly integrated. import java.io.*; import com.itextpdf.text.*; import com.itextpdf.text.pdf.PdfWriter; @org.eclipse.jdt.annotation.NonNullByDefault(true) public class HelloWorld { …
mortiped
  • 869
  • 1
  • 6
  • 28
12
votes
4 answers

Writing to console and text file

I found the code below from the internet, works but it doesn't write the printed console to omt.txt, it only writes the System.out.println statements after the second catch block.If you run the code once you will understand what I mean.All I want is…
Anarkie
  • 657
  • 3
  • 19
  • 46
11
votes
1 answer

con.txt and C++

#include int _tmain(int argc, _TCHAR* argv[]) { std::ofstream F("con.txt", std::ios::out); F << "some text in con.txt"; F.close(); return 0; } output: some text in con.txt If i replace "con.txt" with "something.txt" then…
mr. Vachovsky
  • 1,128
  • 2
  • 13
  • 23
11
votes
2 answers

BitmapFactory.decodeFile returns null even image exists

Saving the file: FileOutputStream fo = null; try { fo = this.openFileOutput("test.png", Context.MODE_WORLD_READABLE); } catch (FileNotFoundException e) { e.printStackTrace(); } bitmap.compress(CompressFormat.PNG, 100,…
stealthcopter
  • 13,964
  • 13
  • 65
  • 83
10
votes
6 answers

File operations in android Q beta

1)Target set to Android Q with android.permission.WRITE_EXTERNAL_STORAGE 2) use getExternalStorageDirectoryor getExternalStoragePublicDirectoryand FileOutputStream(file)saving file throws java.io.FileNotFoundException:…
NitZRobotKoder
  • 1,046
  • 8
  • 44
  • 74
10
votes
4 answers

Read/write file to internal private storage

I'm porting the application from Symbian/iPhone to Android, part of which is saving some data into file. I used the FileOutputStream to save the file into private folder /data/data/package_name/files: FileOutputStream fos = iContext.openFileOutput(…
STeN
  • 6,262
  • 22
  • 80
  • 125
10
votes
1 answer

FileOutputStream equivalent

I am trying to rotate a pdf 180 degrees and I am using the ITextSharp library to do so. The code below is taken from their site's examples. However, I can't seem to find the right namespace to import to get the "FileOutputStream" to work. This is a…
MaylorTaylor
  • 4,671
  • 16
  • 47
  • 76
1
2
3
75 76