java-io

javax.crypto.BadPaddingException: unknown block type

此生再无相见时 提交于 2019-12-05 10:07:37
问题 I am trying to simulate asymmetric key system. I use following code to generate key pairs, encrypt, decrypt passwords. I have a distributed environment and for the moment I save the keys generated in a file system. I know that is not secure but its just for testing purposes. private static SecureRandom random = new SecureRandom(); static { Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider()); } protected synchronized void generateKeys() throws InvalidKeyException,

The FileReader cannot find my text file

僤鯓⒐⒋嵵緔 提交于 2019-12-05 06:32:55
问题 I have a simple text file and for some reason, it cannot be found. I don't see anything wrong with the code because I got it from a site, and I am starting to think that I didn't place the text file in the right place. Any suggestion please? Code: import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; import java.util.ArrayList; import java.nio.file.Path; import java.nio.file.Paths; public class MainFavorites { public static void main(String

Making sure file gets deleted on JVM exit

别来无恙 提交于 2019-12-05 06:09:52
Does File.deleteOnExit() guarantee that the file is deleted even if the JVM is killed prematurely? Deletion will be attempted only for normal termination of the virtual machine, as defined by the Java Language Specification No. check the file at next start-up if possible. Ilmari Karonen As Tim Bender notes, File.deleteOnExit() does not guarantee that the file actually gets deleted. On Unixish systems (such as Linux or OSX), however, it's possible to delete the temporary file before writing to it (but after opening it). As long as you keep an open descriptor to the file, you can keep reading

Read file and write file which has characters in UTF - 8 (different language)

拈花ヽ惹草 提交于 2019-12-05 05:53:56
I have a file which has characters like: " Joh 1:1 ஆதியிலே வார்த்தை இருந்தது, அந்த வார்த்தை தேவனிடத்திலிருந்தது, அந்த வார்த்தை தேவனாயிருந்தது. " www.unicode.org/charts/PDF/U0B80.pdf ‎ When I use the following code: bufferedWriter = new BufferedWriter (new OutputStreamWriter(System.out, "UTF8")); The output is boxes and other weird characters like this: "�P�^����O֛���;�<�aYՠ؛" Can anyone help? these are the complete codes: File f=new File("E:\\bible.docx"); Reader decoded=new InputStreamReader(new FileInputStream(f), StandardCharsets.UTF_8); bufferedWriter = new BufferedWriter (new

create pdf from binary data in java

*爱你&永不变心* 提交于 2019-12-05 02:24:07
问题 I'm getting this string from a web service. " JVBERi0xLjQKMyAwIG9iago8PC9UeXBlIC9QYWdlCi9QYXJlbnQgMSAwIFIKL1Jlc291cmNlcyAyIDAgUgovR3JvdXAgPDwvVHlwZSAvR3JvdXAgL1MgL1RyYW5zcGFyZW5jeSAvQ1MgL0RldmljZVJHQj4" It is supposed to be a pdf file, i tried this library pdfbox from apache, but it writes the content as a text inside the pdf. I've tried with ByteArrayInputStream but the pdf created is not valid, corrupted, this is some of the code i've wrote. public void escribePdf(String texto, String

Java IO : Writing into a text file line by line [closed]

こ雲淡風輕ζ 提交于 2019-12-04 22:08:08
Closed. This question is off-topic . It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 5 years ago . I have a requirement where i need to write a text file line by line. The number of lines may be up to 80K . I am opening the file output stream and inside a for-loop , iterating a list and forming a line and writing the line into the file. This means 80K write operations are made on the file . Opening and writing the file very frequently hinders performance. Can anyone suggest a best way yo address this

Resolving IOException, FileNotFoundException when using FileReader

孤街浪徒 提交于 2019-12-04 20:18:29
I've not been able to resolve the following exception in the code below. What is the problem with the way I use BufferedReader? I'm using BufferedReader inside the main method OUTPUT :- ParseFileName.java:56: unreported exception java.io.FileNotFoundException; must be caught or declared to be thrown BufferedReader buffread = new BufferedReader (new FileReader("file.txt")); // ParseFileName is used to get the file name from a file path // For eg: get - crc.v from "$ROOT/rtl/..path/crc.v" import java.util.regex.Pattern; import java.io.*; public class ParseFileName { //Split along /'s , and

How do I read Windows NTFS's Alternate Data Stream using Java's IO?

限于喜欢 提交于 2019-12-04 17:47:45
I'm trying to have my Java application read all the data in a given path. So files, directories, metadata etc. This also includes one weird thing NTFS has called Alternate Data Stream (ADS). Apparently it's like a second layer of data in a directory or file. You can open the command prompt and create a file in the ADS using ':', for example: C:\ADSTest> echo test>:ads.txt So, C:\ADSTest> notepad :ads.txt Should open a notepad that contains the string "test" in it. However, if you did: C:\ADSTest> dir You will not be able to see ads.txt. However, if you use the dir option that displays ADS data

Need help with pdf-renderer

点点圈 提交于 2019-12-04 15:49:34
I'm using PDF-Renderer to view PDF files within my java application. It's working perfectly for normal PDF files. However, i want the application to be able to display encrypted PDF files. The ecrypted file will be decrypted with CipherInputStream , but i do not want to save the decrypted data on disk. Am trying to figure a way i can pass the decryted data from CipherInputStream to the PDFFile constructor without having to write the decryted data to file. I will also appreciate if someone can help with a link to PDF-Renderer tutorial, so that i can read up more on it. Thanks. Try the following

Reading integer values from binary file using Java

戏子无情 提交于 2019-12-04 13:10:23
I am trying to write values greater than 256 using DataOupPutStream.write() method. When i try reading the same value using DataInputStream.read() it will return 0. So, i used DataOutputStream.writeInt() and DataInputStream.readInt() methods to write and retrieve values greater than 256 and it is working fine. Refer the below code snippet i would like to know the behaviour of the compiler as what it does in the in.readInt() inside the while statement. FileOutputStream fout = new FileOutputStream("T.txt"); BufferedOutputStream buffOut = new BufferedOutputStream(fout); DataOutputStream out = new