Questions tagged [writer]

an abstract class, interface or naming convention which is used to state that the given object is used to write data to a file, stream, device or other destination

A Writer clause is often used as a part of a name of an object in object-oriented programming. Good examples are BufferedWriter from Java 6 or StreamWriter from C#.

Abstract writers are often defined as interfaces or abstract classes to provide means of making the process of writing separable from what is being written. In Java or .NET there are Writer implementations for files, network connections and, more general, streams.

456 questions
297
votes
8 answers

How to append a new row to an old CSV file in Python?

I am trying to add a new row to my old CSV file. Basically, it gets updated each time I run the Python script. Right now I am storing the old CSV rows values in a list and then deleting the CSV file and creating it again with the new list value. I…
laspal
  • 3,337
  • 3
  • 21
  • 10
132
votes
7 answers

Is it necessary to close each nested OutputStream and Writer separately?

I am writing a piece of code: OutputStream outputStream = new FileOutputStream(createdFile); GZIPOutputStream gzipOutputStream = new GZIPOutputStream(outputStream); BufferedWriter bw = new BufferedWriter(new…
Adon Smith
  • 1,849
  • 7
  • 19
  • 19
65
votes
3 answers

Golang Convert String to io.Writer?

Is it possible to convert a string to an io.Writer type in Golang? I will be using this string in fmt.Fprintf() but I am unable to convert the type.
Ari Seyhun
  • 11,506
  • 16
  • 62
  • 109
59
votes
2 answers

Does Python csv writer always use DOS end-of-line characters?

I realize that the csv library in Python always generates DOS end-of-line characters. Even if I use the 'wb' mode, even if I use Linux. import csv f = open('output.txt', 'wb'); writer = csv.writer(f) writer.writerow([2,3,4]); f.close() The above…
CuriousMind
  • 15,168
  • 20
  • 82
  • 120
50
votes
2 answers

Do you need to call Flush() on a stream or writer if you are using the “using” statement?

I am not sure whether I need to call Flush() on the used objects if I write something like this: using (FileStream...) using (CryptoStream...) using (BinaryWriter...) { // do something } Are they always automatically flushed? When does the…
Ben
  • 2,435
  • 6
  • 43
  • 57
50
votes
6 answers

FileInputStream vs FileReader

FileReader rd=new FileReader("new.mp4"); FileWriter wr=new FileWriter("output.mp4"); int ch; while((ch=rd.read())!=-1) wr.write(ch); wr.flush(); wr.close(); When I use the FileReader and FileWriter to read and write an mp4 file, the output.mp4…
saravanan
  • 5,339
  • 7
  • 45
  • 52
39
votes
7 answers

Log4J: How do I redirect an OutputStream or Writer to logger's writer(s)?

I have a method which runs asynchronously after start, using OutputStream or Writer as parameter. It acts as a recording adapter for an OutputStream or Writer (it's a third party API I can't change). How could I pass Log4J's internal OutputStream or…
34
votes
7 answers

What is the difference between append and write methods of java.io.writer?

The java.io.Writer interface has two methods called append and write. What are the differences between these two? It even says that An invocation of this method of the form out.append(c) behaves in exactly the same way as the invocation…
Svish
  • 152,914
  • 173
  • 462
  • 620
33
votes
4 answers

Writing a Python list into a single CSV column

I have a list of numbers that I want to put in a single column in a .csv file. The code below writes the values across a single row. How can I change the code so that Python writes the each value on a separate row? Thanks. with…
user1028861
20
votes
4 answers

When to use which Writer subclass in Java; common practices

I have always been slightly confused with the amount of different IO implementations in Java, and now that I am completely stuck in my project development, I was taking my time to read up on useful stuff meanwhile. I have realized that there is no…
posdef
  • 6,498
  • 11
  • 46
  • 94
20
votes
2 answers

Golang function pointer as a part of a struct

I have the following code: type FWriter struct { WriteF func(p []byte) (n int,err error) } func (self *FWriter) Write(p []byte) (n int, err error) { return self.WriteF(p) } func MyWriteFunction(p []byte) (n int, err error) { // this…
user340495
  • 321
  • 1
  • 4
  • 11
19
votes
1 answer

io.Writer in Go - beginner trying to understand them

As a beginner in Go, I have problems understanding io.Writer. My target: take a struct and write it into a json file. Approach: - use encoding/json.Marshal to convert my struct into bytes - feed those bytes to an os.File Writer This is how I got…
whyme
  • 233
  • 1
  • 3
  • 7
15
votes
1 answer

What is the point of having a lazy/strict version of Writer?

Why are there two different Writer-type monads in Haskell? Intuitively to me, reading "strict writer monad" means that the <> is strict, so that there's no thunk buildup in the log. However, looking at the source code, it turns out that that isn't…
David
  • 8,275
  • 5
  • 26
  • 36
14
votes
3 answers

Write and read from a fifo from two different script

I have two bash script. One script write in a fifo. The second one read from the fifo, but AFTER the first one end to write. But something does not work. I do not understand where the problem is. Here the code. The first script is (the…
Simone
  • 2,304
  • 6
  • 30
  • 79
11
votes
2 answers

Does Writer Monad guarantee right associative concatenation?

It was claimed in Validations in Haskell that use of a Writer guarantees right-associative concatenation. However, this example seems to show otherwise. What's the correct answer? {-# LANGUAGE OverloadedStrings #-} import…
pat
  • 12,587
  • 1
  • 23
  • 52
1
2 3
30 31