fileoutputstream

Writing objects to file while appending [duplicate]

时光毁灭记忆、已成空白 提交于 2019-12-11 19:42:51
问题 This question already has answers here : Write and read multiple objects to file (3 answers) Closed 2 years ago . I have created a program which registers members for a library system. To store the data i have used text files and to read/write i implemented serialization. My problem is when i register one member and try to register another member, the second member records won't get saved. To append writing to the file i used the keyword "true" as well. Here is what i have done: //Am writing

FileOutputStream close when out of space

落爺英雄遲暮 提交于 2019-12-11 19:23:20
问题 I've come across a problem using FileOutputStream and BufferedWriter in Java. If my disk space is full and I'm trying to write, it will throw IOException (which is correct), but when calling the writer.close(), it will fail to close the resource, throwing another IOException and keeping the resource opened! Here is my workaround with writer.flush() . It seems to work, but is there a better way to handle this? BufferedWriter writer = null; try { writer = new BufferedWriter(new

File is not opening in java which is inside jar file

三世轮回 提交于 2019-12-11 17:35:14
问题 I tried to open file form my java application. Using following code from Open PDF file on fly from Java application Code: if (Desktop.isDesktopSupported()) { try { File myFile = new File("/path/to/file.pdf"); Desktop.getDesktop().open(myFile); } catch (IOException ex) { // no application registered for PDFs } } When I use path like : "C:\\Users\\kalathoki\\Documents\\NetBeansProjects\\TestJava\\src\\files\\test.pdf" it opens. But my file is inside my package files/test.pdf and I used files\

Apache POI XSSFWorkbook memory leak

*爱你&永不变心* 提交于 2019-12-11 15:39:58
问题 So I'm making a large-scale prime number generator in Java (with the help of JavaFX). It uses the Apache POI library (I believe I'm using v3.17) to output the results to Excel spreadsheets. The static methods for this exporting logic are held in a class called ExcelWriter. Basically, it iterates through an Arraylist arguments and populates a XSSFWorkbook with it's contents. Afterwords, a FileOutputStream is used to actually make it an excel file. Here are the relevant parts of it: public

Why should we use OutputStream.write(byte[] b, int off, int len) instead of OutputStream.write(byte[] b)?

ⅰ亾dé卋堺 提交于 2019-12-11 15:08:25
问题 Sorry, everybody. It's a Java beginner question, but I think it will be helpful for a lot of java learners. FileInputStream fis = new FileInputStream(file); OutputStream os = socket.getOutputStream(); byte[] buffer = new byte[1024]; int len; while((len=fis.read(buffer)) != -1){ os.write(buffer, 0, len); } The code above is part of FileSenderClient class which is for sending files from client to a server using java.io and java.net.Socket. My question is that: in the above code, why should we

Java Apache POI : Read / Write from .doc file issue

瘦欲@ 提交于 2019-12-11 07:39:19
问题 I am writing a code to read a .doc file as a template and write data in new .doc file after various iterations. My code seems to have some simple issue that I am not able to figure out. Below is the code I have written, [I got basic skeleton somewhere on stackoverflow only.] public class HWPFTest { public static void main(String[] args) { String inputFile = "F:\\docx\\input.doc"; String outputFile = "F:\\docx\\output.doc"; POIFSFileSystem fs = null; try { for (int i = 0; i < 3; i++) { fs =

Smalltalk write a Sorted Collection to a file

廉价感情. 提交于 2019-12-11 03:46:48
问题 let's say i have a SortedCollection called whitepages , each record containing a Customer , with values name and number . I want to create a function which would write them to a file in such way name1 number1 name2 number2 I have to admit Im completely stuck here. Could anyone help? 回答1: Ok, so I hope you know how to write to file. And as you noticed that you have sorted collection I suppose that Customer s are ordered in the way you want. Then what you can do is: (whitepages collect: [

How to copy image to an existing directory on sd card?

隐身守侯 提交于 2019-12-10 22:18:11
问题 I'm trying to copy an image file with this code: InputStream fileInputStream = null; OutputStream fileOutputStream = null; String inPath = "/storage/emulated/0/Pictures/MyImage.jpg"; String outPath = "/storage/extSdCard/MyFolder/MyImage.jpg"; try { verifyStoragePermissions(this); fileInputStream = new FileInputStream(new File(inPath)); File outputFile = new File(outPath); if (!outputFile.exists()) { try { outPutFile.createNewFile(); } catch (IOException e) { e.printStackTrace(); } }

Java FileOutputStream String Writing

☆樱花仙子☆ 提交于 2019-12-10 18:11:40
问题 I’ve been having issues with a Java File. It's designed to write line after line in a test file as a log. Unfortunately it overwrites the same line every time I call it. If anyone can help I would be eternally grateful as this has been driving me up the wall! Code Below. public abstract class Log { protected static String DefaultLogFileLocation = "c:\\LOG.txt"; public static void ToFile(String pInputString) { FileOutputStream pOUTPUT; PrintStream pPRINT; try { pOUTPUT = new FileOutputStream

What character encoding does ObjectOutputStream 's writeObject method use?

。_饼干妹妹 提交于 2019-12-10 16:15:52
问题 I read that Java uses UTF-16 encoding internally. i.e. I understand that if I have like: String var = "जनमत"; then the "जनमत" will be encoded in UTF-16 internally. So, If I dump this variable to some file such as below: fileOut = new FileOutputStream("output.xyz"); out = new ObjectOutputStream(fileOut); out.writeObject(var); will the encoding of the string "जनमत" in the file "output.xyz" be in UTF-16? Also, later on if I want to read from the file "output.xyz" via ObjectInputStream, will I be