inputstream

Access a resource outside a jar from the jar

こ雲淡風輕ζ 提交于 2019-12-28 06:47:31
问题 I'm trying to access a resource from a jar file. The resource is located in the same directory where is the jar. my-dir: tester.jar test.jpg I tried different things including the following, but every time the input stream is null: [1] String path = new File(".").getAbsolutePath(); InputStream inputStream = this.getClass().getResourceAsStream(path.replace("\\.", "\\") + "test.jpg"); [2] File f = new File(this.getClass().getProtectionDomain().getCodeSource().getLocation().toURI().getPath());

Access a resource outside a jar from the jar

人走茶凉 提交于 2019-12-28 06:47:19
问题 I'm trying to access a resource from a jar file. The resource is located in the same directory where is the jar. my-dir: tester.jar test.jpg I tried different things including the following, but every time the input stream is null: [1] String path = new File(".").getAbsolutePath(); InputStream inputStream = this.getClass().getResourceAsStream(path.replace("\\.", "\\") + "test.jpg"); [2] File f = new File(this.getClass().getProtectionDomain().getCodeSource().getLocation().toURI().getPath());

Getting the inputstream from a classpath resource (XML file)

一世执手 提交于 2019-12-27 11:27:06
问题 In Java web application, Suppose if I want to get the InputStream of an XML file, which is placed in the CLASSPATH (i.e. inside the sources folder), how do I do it? 回答1: ClassLoader.getResourceAsStream(). As stated in the comment below, if you are in a multi- ClassLoader environment (such as unit testing, webapps, etc.) you may need to use Thread.currentThread().getContextClassLoader() . See http://stackoverflow.com/questions/2308188/getresourceasstream-vs-fileinputstream/2308388

Getting the inputstream from a classpath resource (XML file)

落爺英雄遲暮 提交于 2019-12-27 11:25:06
问题 In Java web application, Suppose if I want to get the InputStream of an XML file, which is placed in the CLASSPATH (i.e. inside the sources folder), how do I do it? 回答1: ClassLoader.getResourceAsStream(). As stated in the comment below, if you are in a multi- ClassLoader environment (such as unit testing, webapps, etc.) you may need to use Thread.currentThread().getContextClassLoader() . See http://stackoverflow.com/questions/2308188/getresourceasstream-vs-fileinputstream/2308388

Multiple Scanners in Multiple Threads

心已入冬 提交于 2019-12-25 17:45:17
问题 I just encountered a problem concerning the Scanner(System.in) and threads in Java. Suppose you have two threads. In both you wait for an user input using the Scanner to read from the System.in input stream. The Problem is that it is not possible to differentiate which string belongs to which thread (the chars will be spread between both strings seemingly random). I suppose this is because the two threads share the same input stream. Is there a way to work around this issue? 回答1: Synchronized

skia decoder->decode returned false when download image and display in imageview

别来无恙 提交于 2019-12-25 07:46:29
问题 i have a php page which return image from php page in json format $result = mysql_query("SELECT image FROM image_table WHERE email_id = '$email'"); if (!empty($result)) { if (mysql_num_rows($result) > 0) { $result = mysql_fetch_array($result); $user = array(); $user["image"] = base64_encode($result["image"]); $response["success"] = 1; $response["image_table"] = array(); array_push($response["image_table"], $user); echo json_encode($response); } else { $response["success"] = 0; $response[

How to load FileInputStream in a septate class

笑着哭i 提交于 2019-12-25 06:48:08
问题 I've saved two strings to a file and want to display those strings in another class, I tried the usually FileInputStream, but it wasn't having any of it, what other way could I solve this, I want to stick to files and not sharedprefernces. Is there a way to solve this issue with using Inputstreams in another class? Thanks My Code: EditText eTuser; EditText eTpassword; CheckBox StaySignedIn; Button bSubmit; String user; String pass; FileOutputStream fos; FileInputStream fis = null; String

How does input buffering work in C++

岁酱吖の 提交于 2019-12-25 05:30:54
问题 Here is a code snippet. I'm confused as to how the buffering internally works. while(true) { cout << "Enter a character: "; cin.ignore(3, '\n'); ch = cin.get(); // ch is char type cout << "char: ch: " << ch << endl; } Actually cin.ignore(3, '\n') ignores the first three characters and then gets the next immediate character. Till that point its fine. Since, I kept this in a while loop, I was trying to check the behavior of ignore() and get() . For instance, the output for which I checked was

How does InputStream read() in Java determine the number of bytes to read?

孤者浪人 提交于 2019-12-25 05:19:18
问题 http://docs.oracle.com/javase/7/docs/api/java/io/InputStream.html#read() The doc says "Reads some number of bytes from the input stream and stores them into the buffer array b.". How does InputStream read() in Java determine that number of bytes? 回答1: The buffer array has a defined length, call it n . The read() method will read between 1 and n bytes. It will block until at least one byte is available, unless EOF is detected. 回答2: I think the confusion comes from what "read" means. read()

How to specify tab as a record separator for hadoop input text file?

守給你的承諾、 提交于 2019-12-25 05:06:10
问题 The input file to my hadoop M/R job is a text file in which the records are separated by tab character '\t' instead of newline '\n'. How can I instruct hadoop to split using the tab character as by default it splits around newlines and each line in the text file is taken as a record. One way to do it is to use a custom input format class that uses a filter stream to convert all tabs in the original stream to newlines. But this does not look elegant. Another way would be to use java.util