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
9
votes
4 answers

How to set the buffer size on a BufferedWriter over a FileWriter

I met a problem with BufferedWriter when I write data to a single file with some threads. I set the buffer size of the BufferedWriter, but no matter what number I set, it flushes the data to disk when the buffer is 8192 (the default buffer size),…
jinhong_lu
  • 238
  • 1
  • 2
  • 11
9
votes
3 answers

The system cannot find the path specified with FileWriter

I have this code: private static void saveMetricsToCSV(String fileName, double[] metrics) { try { FileWriter fWriter = new FileWriter( System.getProperty("user.dir") + "\\output\\" + …
rfgamaral
  • 16,546
  • 57
  • 163
  • 275
9
votes
2 answers

Performance: BufferedOutputStream vs FileWriter

I've always used a FileWriter to write text to a file in Java. Apparently you can also use a BufferedOutputStream as well. After reading both javadocs carefully, I can't seem to tell which was is faster/more efficient. So I ask: is there a…
user1768830
8
votes
2 answers

Writing to a file in Apache Spark

I am writing a Scala code that requires me to write to a file in HDFS. When I use Filewriter.write on local, it works. The same thing does not work on HDFS. Upon checking, I found that there are the following options to write in Apache Spark-…
kruparulz14
  • 163
  • 1
  • 3
  • 12
7
votes
2 answers

Downloading file from DataURL in JavaScript

From this string we get from DataURL, what's the best way to download this as a file? So far what I got was using a basic window.open("myDataURL");, but I'm not able to change the file name in this…
eBergamo
  • 101
  • 3
  • 6
7
votes
2 answers

Java FileWriter - Append Line of Text File

I have a button in a GUI, and when the button is pressed the user has the ability to add information to a text file. I have this part setup fine, but the thing that is messing with me is that when the user writes to the file it erases all the info…
rjdelight
  • 83
  • 1
  • 3
  • 7
7
votes
4 answers

Append a character for last value in a list in JAVA

Given this…
Anusha
  • 939
  • 3
  • 13
  • 31
7
votes
2 answers

Java File Writing Randomly stops?

This one's got me going crazy. I have the following code that reads a csv file and re-formats it into a copy paste ready java array format: CSVReader reader = new CSVReader(new FileReader(fileName), ',' , '"' , 0); FileWriter writer = new…
Clint L
  • 1,093
  • 5
  • 12
  • 29
7
votes
9 answers

Copying the Contents of One text file to Another in Java

I am trying to copy the contents of one text file ("1.txt") which contains 2-3 integer numbers (ex: 1 2 3) to another text file ("2.txt") but I am getting the following error upon compilation import java.io.*; class FileDemo { public static void…
Salman
  • 109
  • 2
  • 4
  • 10
6
votes
2 answers

Directory does not exist with FileWriter

I use FileWriter for create a file. I have an error Directory does not exist I think that FileWriter create the directory if it did not exist FileWriter writer = new FileWriter(sFileName);
Mercer
  • 9,736
  • 30
  • 105
  • 170
6
votes
4 answers

java - Does FileWriter use a buffer? (it acts like it does in my example)

I am using FileWriter and I have noticed strange behavior. I buffer my collection myself and every x rows I use IOUtils.writelines(myList,"\n", writer ); It doesnt write to the file. I continue to call it with more lines and only after it is…
Bick
  • 17,833
  • 52
  • 146
  • 251
6
votes
2 answers

TensorFlow FileWriter not writing to file

I am training a simple TensorFlow model. The training aspect works fine, but no logs are being written to /tmp/tensorflow_logs and I'm not sure why. Could anyone provide some insight? Thank you # import MNIST from tensorflow.examples.tutorials.mnist…
user4884986
6
votes
1 answer

How to overwrite a file in Chrome App?

I followed this example: chrome.fileSystem.chooseEntry({type:'openDirectory'}, function(entry) { chrome.fileSystem.getWritableEntry(entry, function(entry) { entry.getFile('file1.txt', {create:true}, function(entry) { …
Freewind
  • 193,756
  • 157
  • 432
  • 708
6
votes
1 answer

cordova 3.0 FileWriter THREAD WARNING: exec() call to File.write blocked the main thread...should use CordovaInterface.getThreadPool()

I'm using the FileWriter and it works fine except for these messages in the logcat when I write largish files of various sizes upto about 3MB. I had a look at the FileUtils.java source and the write function doesn't use the getThreadPool() interface…
6
votes
1 answer

PrintWriter not printing out complete string

I have the following code FileWriter F = new FileWriter("out.txt"); PrintWriter H = new PrintWriter(F); H.print(split[split.length - 2]); H.print("END"); When I examine the txt however, the last text is NOT 'END', but part of a word in the string.…
DreamsOfHummus
  • 735
  • 2
  • 7
  • 18
1 2
3
75 76