Skip to main content

All Questions

Tagged with
Filter by
Sorted by
Tagged with
0 votes
1 answer
88 views

Write String values in Writer object with Java 8 Stream

I'm trying to replace an ordinary for loop which writes String values in a Writer object with stream in the following code: public void save() { try (Writer fileWriter = new FileWriter(file)) { ...
user301's user avatar
  • 11
0 votes
1 answer
204 views

Java Embeded Closeable Resource in Try - With Statement

Here's a simple code. try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File("c:\\hello.txt"))));) { writer.write("...
user3009097's user avatar
0 votes
0 answers
364 views

error on line 2 at column 6: XML declaration allowed only at the start of the document (JAVA) [duplicate]

I am making API xml using marshaller. It works well, when I set Property(JAXB_FRAGMENT, Boolean.FALSE) but the result shows without an XML declaration.. I want to generate an XML declaration like &...
hayley's user avatar
  • 45
0 votes
0 answers
26 views

Writer inside a class does not work in a driver

I have a Java console application which has different views for different users. Inside of each view I have writer and reader, which are used to displaying and getting data. But when I start my driver ...
Chingis Bagdatov's user avatar
0 votes
2 answers
45 views

Read CSV and write two differents xml files - best practices

I have a batch that reads a .csv file and maps its data into a POJO. I need to write two XML files as output. Currently, to write these two files, I generated classes via XJC from their XSD. I am ...
lasnico37's user avatar
1 vote
1 answer
107 views

Best way to sort strings of filepaths into a directory structure?

I am using contentService.streamDirectory to get a callback containing all directories/files within a BitBucket project, then I am using a for loop and "callback.getFiles().get(i).toString()"...
MillieJA's user avatar
0 votes
0 answers
1k views

Taking too long time for writing the data in CSV file in java

Taking a too long time to write the data in the CSV file in java. Here I am writing the data into the CSV file. 100,000 records it takes 1hr 10 minutes to write into a csv file. But query takes 2 ...
Sriram Kumar's user avatar
0 votes
1 answer
202 views

Assert OutputStreamWriter contains correct instance of OutputStream

I'm writing a test for a method that returns Writer for different extension files. For .gz returns new OutputStreamWriter(new GZIPOutputStream(new FileOutputStream(file)), StandardCharsets.UTF_8) For ...
Poli's user avatar
  • 77
1 vote
3 answers
513 views

For loop to write data to file Java

I need to implement a method called saveWorksToFile according to the Javadoc in the code. The format of the output written to the file should be the following this pattern: where ARTIST_NAME is the ...
HY2000's user avatar
  • 181
0 votes
1 answer
209 views

Is there a way to delete the PDF byte array and html file? [duplicate]

I'm trying to delete the byte array PDF and HTML file after it has been generated and the PDF is saved to a byte array Document to save server space usage. The Writer class and the pdf byte array do ...
newbie's user avatar
  • 105
0 votes
1 answer
1k views

Can I make Spring step to commit to db in first step before waiting next step?

Good day, I have a Spring batch that using different step, the Job is something like follow: @Bean public Job myJob() throws Exception { return jobBuilderFactory.get("MyJob")....
Panadol Chong's user avatar
0 votes
1 answer
2k views

Java: How can I update the existing csv file and not create a new one?

I am writing to a csv file and then later updating it. But with. my update code, a new same file is generated. Below is my code and I was wondering how I can update without creating a new file. ...
Atihska's user avatar
  • 5,118
0 votes
1 answer
79 views

How to read from file in Java with confirm attributes

Is it possible to determine the properties of an object after it is read from a file in Java? Suppose I write a list of students (name, age, grades,...) into the file "student.txt". When I ...
hoang_Liu's user avatar
1 vote
0 answers
201 views

How to write to an ongoing console

I am making a java program that takes an input and puts it to another console (windows). The thing is, the other console is a Minecraft server that is in the middle of running. The console has a > ...
YHDiamond's user avatar
  • 134
3 votes
1 answer
4k views

Specify Header and Footer for all file created by MultiResourceItemWriter when writing in multiples files -spring batch

I have a batch that read from data base using JdbcPagingItemReader, process each record from the database in a java class then write it to a file using FlatFileItemWriter. It appends also a header and ...
Abenamor's user avatar
  • 318
1 vote
1 answer
398 views

How PrintWriter can write to byte stream, but BufferedWriter cannot?

To start with I will provide a piece of code with comments: FileOutputStream fos = new FileOutputStream ("test.txt"); //fos IS-A OutputStream as FileOutputStream extends OutputStream ...
Stefan's user avatar
  • 1,039
0 votes
1 answer
4k views

Exception in thread "main" java.nio.file.InvalidPathException: Illegal char <:> at index 72

can someone help me with this one, im having a error like this Exception in thread "main" java.nio.file.InvalidPathException: Illegal char <:> at index 72: D:/Users/cleyeza/Desktop/...
paroxysm04's user avatar
0 votes
1 answer
492 views

Can I use spring batch writer to for both HTTP post request and write to db

I would like to read a list of records from DB, then iterate over it, and perform the following actions for each record: Resolve data for generating JSON body, and send HTTP post request. Update DB, ...
Ilan Miller's user avatar
1 vote
1 answer
928 views

Is there a way to check for duplicate lines within a file using Java?

I'm attempting to read each line within an .inp file and for every non-duplicate, write the line to a new file. The issue I'm running into with the code I have so far is that all lines are written ...
Bianca's user avatar
  • 15
0 votes
1 answer
141 views

I can't write on multiple lines in a txt file in java

So I'm trying to write in a text file, nothing too complicated, but for some reason the new text that i want to add doesn't change lines, it keeps going on the same line, and I can't figure out why. ...
Alex Bidenia's user avatar
1 vote
1 answer
569 views

Read UTF-8 properties file and save as UTF-8 txt file

I am currently trying to analyze all of my properties files and need my properties files in the form of a .txt file for one part. The problem is that german "Umlaute" like Ä,Ü,Ö etc. are not taken ...
Pascal's user avatar
  • 23
1 vote
1 answer
141 views

Is there a way to use a Java Writer object to write binary data?

I want to use the writeSearchResults method of this Jira plugin interface. The description of the interface says that it should be possible to generate PDF files but I am not sure how to do this ...
user12687708's user avatar
3 votes
1 answer
3k views

File Write in resource folder in jar

I've a resource folder(files) in my java swing project which contains a text file (users.txt), I'm reading and writing data into that text file. When i export it as jar file, reading from that file is ...
Shahab's user avatar
  • 43
2 votes
1 answer
796 views

How to implement a Reader/Writer program using threads?

I have an issue with a Reader/Writer implementation. I'm supposed to write a Reader class that takes a String from the console and adds it to a Queue and a Writer class that removes the String from ...
Raighley's user avatar
1 vote
2 answers
333 views

How to make PrintWriter write in log-in screen or in any text box I choose in windows 10

I am writing a java program to print password in log-in page of windows 10 (to get automatically login when I do some action) I try to use printwriter to do that . I managed to print the text inside ...
Hasan_Naser's user avatar
0 votes
1 answer
535 views

Can we use two buffered writers to write on the same file with java, in the same class?

I have been wondering if I cam use two bufferedWriters to write an external file with java. This is what I did: But there is only written X in my created file, any ideas ? It seems like the file ...
Mehdi Zayene's user avatar
-2 votes
2 answers
204 views

Writer in java static method

I have used the writer before but for some reason I am having trouble implementing it in the following method. I have never put the writer in a static method. //replace an empty seat with a ...
Bryce Lynch's user avatar
1 vote
1 answer
54 views

Using Writer to send an email with Korean text outputs garbage

My app programmatically sends emails. It works when the body is English text, but when the body is Korean it comes out as garbage. For example sending '테스트' results in '???'. Here's the code I'm ...
alex87's user avatar
  • 432
0 votes
5 answers
68 views

Write and close BufferedWriter in single line code snippet

I've below code snippet. Map<String, Object> globalMap = new HashMap<String,Object>(); File talendLogFile = new File("C:\\Softwares\\logFiles\\error.log"); Writer talendLogFileWriter = ...
Trisha's user avatar
  • 51
0 votes
1 answer
373 views

How to copy a xml record from a xml file to another file using Java programming?

I have some xml records as below <records> <record> <name>SK</name> <age>30</age> </record> <record> <name>KK</name> <age>10</...
Sujatha Rajesh's user avatar
1 vote
2 answers
66 views

bufferedwriter refuses to write to text file(Java)

Whenever I call my method in my code, despite opening and closing my BufferedWriter correctly(I think) it still refuses to print to the text file that it is meant to print to Here is my code : ...
Phillip Drake's user avatar
-1 votes
2 answers
36 views

See size and the content of file (the new added strings) while writing to it in java after each refresh

I have used PrintWriter to write to a text file with java, the process takes time, bcz there is an iteration process, at end of each iteration, a string is appended to the file, if I wait till the ...
user9322960's user avatar
1 vote
1 answer
558 views

Calling java methods from inside servlet

I new with servlet programming and I am trying to create and write a file from following java method- public void file() throws FileNotFoundException, UnsupportedEncodingException { PrintWriter ...
S M's user avatar
  • 100
0 votes
2 answers
2k views

BufferedWriter without try method IOException

I know this topic has been discussed a lot and I have already read a lot of posts here about that, but I still seem to have trouble. My problem is that I am also a beginner and I don't really ...
darthvader211's user avatar
0 votes
2 answers
47 views

Java Writer stopping after single write

I'm looking to read the contents of a URL and write them to file, this is working as expected but it's only writing it a single time even though the program console shows multiple lines. Code: ...
Colin747's user avatar
  • 5,003
0 votes
1 answer
508 views

Java - Can't delete file using File .delete()

so I'm using the following code to basically delete one line from a file by writing a temporary file with everything but that one line and then deleting the old file and setting the new files name to ...
user avatar
1 vote
0 answers
23 views

for Loop 2d array BufferedWriter is not writing to txt

I have this code: try { File file = new File("newbook.txt"); FileWriter fw = new FileWriter(file, true); BufferedWriter out = new BufferedWriter(fw); if (!file....
Mark Yo's user avatar
  • 49
0 votes
1 answer
5k views

Spring Batch - write to 2 tables at once

I have a Person object that has a list of addresses. My Spring Batch app converts Person JSON recors into Person POJOs and writes them to a database. Ordinarily, I'd use JdbcBatchItemWriter but I see ...
TheCoder's user avatar
  • 8,883
1 vote
1 answer
106 views

BufferedWriter don't write txt file

Can someone help me to resolve my issue? I have problem that BufferedWriter does not write to text file. Program compiles without errors. int number_of_line_to_delete_in_file = 0,...
Rafał Biel's user avatar
0 votes
2 answers
10k views

Write object to zip file in json format

My goal is to write an object to zip file in json format. The simplest way of doing it is: ZipOutputStream zip = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(zipFile))); String ...
lukasz's user avatar
  • 51
1 vote
2 answers
3k views

Blank pages in pdf after downloading it from web

I am trying to download a PDF file with HttpClient, it is downloading the PDF file but pages are blank. I can see the bytes on console from response if I print them. But when I try to write it to file ...
Manvi's user avatar
  • 1,156
10 votes
2 answers
14k views

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 ...
Ramesh Raj's user avatar
1 vote
3 answers
874 views

Java PrintWriter File Overwrite

I want to write into a file using UTF-16 so I use PrintWriter(file,"UTF-16"), but then it deletes everything in the file, I could use FileWriter(file,true), but then it wouldn't be in UTF-16, and ...
DSOI__UNUNOCTIUM's user avatar
0 votes
2 answers
40 views

When are readers/writers/streams identified as being open?

I am creating an abstract binding class for a Reader and Writer where the user doesn't have to reference each one individually. Example: I have a FileStream which inside of it houses both a ...
user avatar
0 votes
0 answers
34 views

How to create a java.io.Writer from a file without clean the file in java? [duplicate]

I have the code below. Writer v_fw = new FileWriter(v_sheetWrapper.getFile()); Where getFile() is an XML file filled with my code. When I create the Writer through the code above, The XML file is ...
user1863014's user avatar
1 vote
1 answer
3k views

Writing columns into a text file

Before tagging my question as a duplicate question, please let me explain first! I know using String.format will let the text to be written into two columns, but that is not what I need. Because ...
lonesome's user avatar
  • 2,552
0 votes
1 answer
654 views

BufferedWriter does not write to file after flush and close

I have following sample application in which I write to a file and immediately after closing the writer, I try to read from the file but to my surprise nothing is written to file. I have made sure ...
Bagira's user avatar
  • 2,283
-3 votes
4 answers
520 views

java why with general imports not compiling

I wrote a program that writes a line to a file. When I use more general imports, it doesn't compile while with these imports it works: import java.nio.file.*; import java.io.File; import java.io....
Liz's user avatar
  • 11
-1 votes
1 answer
51 views

How can I print each line from a Reader

so i am working on a project where I am making an SMTP server. I am trying to read in each line of input and then hand that line to another thread for processing. However, with this code, the lines ...
yasgur99's user avatar
  • 838
0 votes
3 answers
1k views

Input/Output on a file

I wrote a short program for one of my class and there is something that I just cannot figure out. So I am supposed to write 100 random integers on a file, read back the data and print the integers in ...
Mbris's user avatar
  • 1