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.

1082 questions
203
votes
9 answers

Java FileOutputStream Create File if not exists

Is there a way to use FileOutputStream in a way that if a file (String filename) does not exist, then it will create it? FileOutputStream oFile = new FileOutputStream("score.txt", false);
Stefan Dunn
  • 4,833
  • 7
  • 41
  • 77
91
votes
17 answers

file.delete() returns false even though file.exists(), file.canRead(), file.canWrite(), file.canExecute() all return true

I'm trying to delete a file, after writing something in it, with FileOutputStream. This is the code I use for writing: private void writeContent(File file, String fileContent) { FileOutputStream to; try { to = new…
Jenny Smith
  • 2,807
  • 6
  • 25
  • 32
86
votes
2 answers

How to write data with FileOutputStream without losing old data?

If you work with FileOutputStream methods, each time you write your file through this methods you've been lost your old data. Is it possible to write file without losing your old data via FileOutputStream?
iSun
  • 1,526
  • 6
  • 26
  • 53
71
votes
6 answers

Android download binary file problems

I am having problems downloading a binary file (video) in my app from the internet. In Quicktime, If I download it directly it works fine but through my app somehow it get's messed up (even though they look exactly the same in a text editor). Here…
Isaac Waller
  • 32,041
  • 27
  • 93
  • 107
52
votes
2 answers

Android Error - Open Failed ENOENT

I am trying to save some block coverage using an array of integers that simply saves the number of times a block is executed. For some reason, though, when I try and write to some files that I created ("BlockForHelper.txt" for example, which I made…
NioShobu
  • 775
  • 2
  • 10
  • 21
47
votes
2 answers

At what point does wrapping a FileOutputStream with a BufferedOutputStream make sense, in terms of performance?

I have a module that is responsible for reading, processing, and writing bytes to disk. The bytes come in over UDP and, after the individual datagrams are assembled, the final byte array that gets processed and written to disk is typically between…
Thomas Owens
  • 107,741
  • 94
  • 299
  • 427
46
votes
5 answers

Get file name from FileOutputStream

Is there a way to get the file name from a FileOutputStream or from FileInputStream?
Ebbu Abraham
  • 1,986
  • 5
  • 21
  • 30
32
votes
4 answers

FileOutputStream crashes with "open failed: EISDIR (Is a directory)" error when downloading image

I'm trying to download an iamge from the internet, Here is the code: try { String imgURL = c.imgURL; String imgPATH = c.imgPATH; URL url = new URL(imgURL); URLConnection conexion =…
Omar
  • 7,085
  • 13
  • 58
  • 106
27
votes
8 answers

How to overwrite one property in .properties without overwriting the whole file?

Basically, I have to overwrite a certain property in a .properties file through a Java app, but when I use Properties.setProperty() and Properties.Store() it overwrites the whole file rather than just that one property. I've tried constructing the…
user890704
23
votes
2 answers

FileOutputStream: Does the "close" method calls also "flush"?

I'm really confused about flush and close method.In my code I always close my FileOutputStream object. But I want to know that if I have to use flush method here, and where can I use it? I will write a project that download 4 or 5 files repeatedly.…
javauser35
  • 925
  • 2
  • 8
  • 22
22
votes
10 answers

How to overwrite/reuse the existing output path for Hadoop jobs again and agian

I want to overwrite/reuse the existing output directory when I run my Hadoop job daily. Actually the output directory will store summarized output of each day's job run results. If I specify the same output directory it gives the error "output…
yogesh
  • 231
  • 1
  • 2
  • 5
20
votes
2 answers

How do you play Android InputStream on MediaPlayer?

So I have a small audio file in my assets folder and I wanted to open a InputStream to write to a buffer, then write to a temporary File, then I open up the MediaPlayer to play that temporary File. Problem is, when the media player hits…
Rion
  • 505
  • 1
  • 3
  • 9
19
votes
4 answers

How to write new line in Java FileOutputStream

I want to write a new line using a FileOutputStream; I have tried the following approaches, but none of them are working: encfileout.write('\n'); encfileout.write("\n".getbytes()); encfileout.write(System.getProperty("line.separator").getBytes());
Pavan Patidar
  • 243
  • 1
  • 2
  • 9
17
votes
6 answers

why sometime it throws FileNotFoundException

The code works for most of the time, but some time it throws exception. Couldn't figure out what could cause it. What is does is to create a file at /storage/emulated/0/Download/theFileName.jpg and write data to it (from sourceFile which does…
lannyf
  • 6,775
  • 4
  • 49
  • 92
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
  • 7,212
  • 8
  • 34
  • 53
1
2 3
72 73