Questions tagged [filewriter]

Java built-in class that allows writing character files.

Public class FileWriter extends OutputStreamWriter.

Convenience class for writing character files. The constructors of this class assume that the default character encoding and the default byte-buffer size are acceptable. To specify these values yourself, construct an OutputStreamWriter on a FileOutputStream.

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 FileWriter (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.

FileWriter is meant for writing streams of characters. For writing streams of raw bytes, consider using a FileOutputStream.

Since: JDK1.1

Source: Oracle

1133 questions
14
votes
6 answers

Modify the content of a file using Java

I want to delete some content of file using java program as below. Is this the write method to replace in the same file or it should be copied to the another file. But its deleting the all content of the file. class FileReplace { …
Adesh singh
  • 2,083
  • 9
  • 24
  • 36
14
votes
3 answers

Trouble with filewriter overwriting files instead of appending to the end

OK, I'm having some trouble writing multiple lines to a text file. the program runs, but it won't use new lines each time when I want it run 4 times, the text file should look like: a b c d instead, it looks like: d who knows how to fix this…
Azulflame
  • 1,534
  • 2
  • 15
  • 30
13
votes
2 answers

fs.writeFile() writes [object, object] instead of actual objects when closing script

My script needs to read and write from a JSON file. This works without problems. I copy the file locally, edit the object, and write them back out to the file. However, when I close the script with Ctrl+C and check my file it has [object, object]…
brabant
  • 135
  • 1
  • 1
  • 7
13
votes
4 answers

How to append text to file in Java 8 using specified Charset

I'm looking for an easy and save solution to append text to a existing file in Java 8 using a specified Charset cs. The solution which I found here deals with the standard Charset which is a no-go in my situation.
principal-ideal-domain
  • 3,998
  • 8
  • 36
  • 73
12
votes
3 answers

Java writing to a deleted file

I'm using FileWriter to write to a file and noticed that even after I have deleted the file (out of process) the FileWriter does not throw any exception. Is this normal?
DD.
  • 21,498
  • 52
  • 157
  • 246
12
votes
2 answers

Force download for blob created with FileWriter in JavaScript

HTML5 introduces the FileWriter class. With this class you can make Blobs. (A File is an extension of a Blob.) With JavaScript you can make a Blob and for instance show it using the dataURL. Example: var bb = new BlobBuilder(); bb.append('some…
Rudie
  • 52,220
  • 42
  • 131
  • 173
12
votes
5 answers

FileWriter out of memory

I want to format and write the contents of a large Map (1.785.530 entries) to a text file. After about 85% of the entries are processed, it gets very slow and then I get an OutOfMemoryException. This same error occurs, even if I: periodically call…
userSJ
  • 125
  • 1
  • 7
12
votes
3 answers

Why is FileWriter not creating a new file ? FileNotFoundException

So I have a code snippet as follows. Im trying to find out why it throws a FileNotFoundException. File file= new File (WORKSPACE_PATH+fname); FileWriter fw; if (file.exists()) { fw = new FileWriter(file,true);//if file exists append to file.…
seeker
  • 6,841
  • 24
  • 64
  • 100
12
votes
1 answer

Example for file read/write with NSFileHandle

Are there good examples for doing file read/write in chunks with objective c? I am new to objective-c and iPhone API, here is the sample code that I wrote. Are there better ways to do it? -(void) performFileOperation { @try { …
ssk
  • 9,045
  • 26
  • 96
  • 169
11
votes
4 answers

Java - How to detect file deletion while writing to a file?

Our java program writes some important data into a file continuously. Now we want to thrown some exception or display some kind of error message on the console whenever the file (to which the java program is writing) is deleted by some user…
Amit
  • 33,847
  • 91
  • 226
  • 299
10
votes
2 answers

Using the HTML5 FileWriter truncate() method?

I'm experimenting with the HTML5 File API, and I'm needing to use a method which I don't know enough about (simply because it's hardly documented anywhere). I'm talking about the FileWriter truncate() method, and I know it does what I need to do.…
caleb531
  • 4,111
  • 6
  • 31
  • 41
10
votes
5 answers

Save PNG Canvas Image to HTML5 Storage (JAVASCRIPT)?

I am developing a chrome extension. I open an image file in canvas, I apply some changes to it, then I am trying to save it to the HTML5 filesystem api. First I get the dataURL from the canvas: var dataURL =…
Rob
  • 101
  • 1
  • 1
  • 3
10
votes
2 answers

Writer not working for json file using Gson ,json file is blank after code execution

I'm trying to write json data to a json file. After code execution no errors are thrown but the .json file is empty. Please find below code and help on this import java.io.BufferedWriter; import java.io.FileWriter; import java.io.IOException; import…
Ramesh Raj
  • 185
  • 1
  • 2
  • 13
10
votes
4 answers

Write JSON to a File

I have a class compositionJSON. The class has a method calls makeJSONObject, that creates a JSON-Object and put stuff in it. Here is the code of the class. public class CompositionJso extends JSONObject { public JSONObject makeJSONObject (String…
dudi
  • 5,523
  • 4
  • 28
  • 57
10
votes
2 answers

Writing to an already existing file using FileWriter Java

Is there anyway I can write to an already existing file using Filewriter For example when the user clicks a submit button: FileWriter writer = new…
delo
  • 121
  • 1
  • 2
  • 4
1
2
3
75 76