java-io

create pdf from binary data in java

耗尽温柔 提交于 2019-12-03 17:12:39
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 rutaSalida) throws IOException{ byte[] biteToRead = texto.getBytes(); InputStream is = new

java.io.FileNotFoundException on an existing file

被刻印的时光 ゝ 提交于 2019-12-03 14:40:59
I am getting this error when I try to open a file: java.io.FileNotFoundException: D:\Portable%20Programs\Android%20Development\workspace3\XXX-desktop\bin\World_X.fr (The system cannot find the path specified) at java.io.FileInputStream.open(Native Method) at java.io.FileInputStream.<init>(Unknown Source) at java.util.Scanner.<init>(Unknown Source) The file is existing in the directory but I am still getting this error. However when I copy the same file in the Eclipse workspace Project src folder, no such Exception is returned (though this method also creates the World_X.fr file in the bin

Should I buffer the InputStream or the InputStreamReader?

梦想与她 提交于 2019-12-03 10:43:16
问题 What are the differences (if any) between the following two buffering approaches? Reader r1 = new BufferedReader(new InputStreamReader(in, "UTF-8"), bufferSize); Reader r2 = new InputStreamReader(new BufferedInputStream(in, bufferSize), "UTF-8"); 回答1: r1 is more efficient. The InputStreamReader itself doesn't have a large buffer. The BufferedReader can be set to have a larger buffer than InputStreamReader . The InputStreamReader in r2 would act as a bottleneck. In a nut: you should read the

Java (J2SE) DTMF tone detection

不想你离开。 提交于 2019-12-03 09:02:47
I am trying to do the following I am getting a call to another person using my java application (Already done & works fine). Then I am playing a recording, for example "Please press 1 one to continue in english" (Already done & works fine). Now I want to detect that person press one, As per my researches in google search I got that this can do using DTMF.If the person press 1 I want to do the actions according to my condition. My question is how to detect that number using DTMF in java (J2SE). I am using ZTE USB dongle to make the call. Dialing, Hangup, And other controls did by using AT

what is the difference in using InputStream instead of FileInputStream while creating the FileInputStream object

て烟熏妆下的殇ゞ 提交于 2019-12-03 07:05:30
问题 This may be a silly one, but I want to know the background operation difference. InputStream is = new FileInputStream(filepath); FileInputStream is = new FileInputStream(filepath); What is the difference between the above two lines of code and in what scenarios are they used. 回答1: FileInputStream extends InputStream : it is a specialized version of an InputStream designed for reading files. There are several implementations of an InputStream according to the use of it. It is usually good

InputStream, mark(), reset()

拥有回忆 提交于 2019-12-03 05:48:37
How are mark() and reset() methods working exactly(in code below), step by step ? I tried to write my own example but is starts to throw wrong mark exception or similar to that, and I cannot understand what is the point of placing mark and reset methods in this code because I don't see difference with this or without. import java.io.*; class BufferedInputStreamDemo { public static void main(String args[]) { String s = "© is a copyright symbol, " + "however &copy isn't.\n"; byte buf[] = s.getBytes(); ByteArrayInputStream in = new ByteArrayInputStream(buf); int c; boolean marked = false; //try

Blocking in terms of java.io/java.nio

 ̄綄美尐妖づ 提交于 2019-12-02 22:52:28
问题 I just read ... Classes that work with streams are located in two packages: java.io and java.nio. Classes from the former implement blocking of input/output (I/O): When bytes are being read/written by a process, they become unavailable for other threads of execution. The latter package offers non-blocking I/O with improved performance. ... and would like to understand this a bit more. Does blocking only impact the single relevant thread, but leave the source (i.e. file or database) itself

what is the difference in using InputStream instead of FileInputStream while creating the FileInputStream object

白昼怎懂夜的黑 提交于 2019-12-02 20:42:35
This may be a silly one, but I want to know the background operation difference. InputStream is = new FileInputStream(filepath); FileInputStream is = new FileInputStream(filepath); What is the difference between the above two lines of code and in what scenarios are they used. FileInputStream extends InputStream : it is a specialized version of an InputStream designed for reading files. There are several implementations of an InputStream according to the use of it. It is usually good practice to use the highest type needed in your code. Therefore if your code needs to read data from an

How to copy image in java using bufferedreader/writer

末鹿安然 提交于 2019-12-02 19:37:51
问题 File file = new File("download.png"); File newfile = new File("D:\\Java.png"); BufferedReader br=null; BufferedWriter bw=null; try { FileReader fr = new FileReader(file); FileWriter fw = new FileWriter(newfile); br = new BufferedReader(fr); bw = new BufferedWriter(fw); char[] buf = new char[1024]; int bytesRead; while ((bytesRead = br.read(buf)) > 0) { bw.write(buf, 0, bytesRead); } bw.flush(); } catch (Exception e) { e.printStackTrace(); } finally { try { br.close(); bw.close(); } catch

Updating a bundled resource file

狂风中的少年 提交于 2019-12-02 16:19:21
问题 I am doing the following, String str = "this is the new string"; URL resourceUrl = getClass().getResource("path_to_resource"); File file = new File(resourceUrl.toURI()); BufferedWriter writer = new BufferedWriter(new FileWriter(file)); writer.write(xml); writer.close(); In the above code I am trying to write to a resource file contained in one of my java packages. After executing the code, my program executes fine but the file just updates the properties file in web-INF and not into the