inputstream

how to read socket input stream in Android

两盒软妹~` 提交于 2019-12-23 18:38:34
问题 can anybody tell me how to read socket input stream. Here is my code. if (!serverIpAddress.equals("")) { try { InetAddress serverAddr = InetAddress.getByName(serverIpAddress); Log.i("ClientActivity", "Connecting..."); Socket socket = new Socket(serverAddr, 5777); try { Log.i("ClientActivity", "Sending command."); PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(socket .getOutputStream())), true); // where you issue the commands out.println("<maplist />"); Log.i(

Reading a Text File From a .jar File

旧城冷巷雨未停 提交于 2019-12-23 13:08:09
问题 I have a rookie question. I'm currently writing a program that takes in alot of data from a text file using the File and Scanner class as shown below: File data = new File("champdata.txt"); Scanner read = new Scanner(data); read.useDelimiter("%"); The Scanner then retrieves data from the text file correctly while in the IDE, but when I run the program as a .jar file, the file cannot be retrieved. I've read a little about adding a text file to the .jar file itself, and using the InputStream

Java-Sockets: InputStream.read() vs BufferedReader.read()

人走茶凉 提交于 2019-12-23 11:59:13
问题 I'm reading from a Socket's InputStream. Because I'm parsing the incoming data on the fly, I'm required to read character by character. Does BufferedReader.read() the same thing as InputStream.read() does ? (assuming that BufferedReader has been constructed with the InputStream as base) Is it more efficient to use InputStream.read() when reading each character separately? Or is there any better way? 回答1: BufferedReader will read multiple characters from an underlying Reader. An InputStream is

Java .class.getResourceAsStream()

倾然丶 夕夏残阳落幕 提交于 2019-12-23 09:48:48
问题 To the best of my knowledge, Class.getResourceAsStream() gets an InputStream directed at a file within the .jar file? If I'm wrong about this, please correct me. Is there any way to temporarily 'load' an external file into the .jar, so that the getResourceAsStream() method can retrieve it? For example loading C:/folder/file.txt into the .jar so that MyClass.class .getResourceAsStream("file.txt") would return a working InputStream to the file, or at least a copy of it that has been 'loaded'

Good design: How to pass InputStreams as argument?

こ雲淡風輕ζ 提交于 2019-12-23 08:46:34
问题 I've got a big file on which I'm opening a FileInputStream. This file contains some files each having an offset from the beginning and a size. Furthermore, I've got a parser that should evaluate such a contained file. File file = ...; // the big file long offset = 1734; // a contained file's offset long size = 256; // a contained file's size FileInputStream fis = new FileInputStream(file ); fis.skip(offset); parse(fis, size); public void parse(InputStream is, long size) { // parse stream data

Good design: How to pass InputStreams as argument?

痴心易碎 提交于 2019-12-23 08:46:23
问题 I've got a big file on which I'm opening a FileInputStream. This file contains some files each having an offset from the beginning and a size. Furthermore, I've got a parser that should evaluate such a contained file. File file = ...; // the big file long offset = 1734; // a contained file's offset long size = 256; // a contained file's size FileInputStream fis = new FileInputStream(file ); fis.skip(offset); parse(fis, size); public void parse(InputStream is, long size) { // parse stream data

How can I convert InputStream data to String in Android SOAP Webservices

旧城冷巷雨未停 提交于 2019-12-23 08:36:14
问题 When I am consuming the soap web services from Android I want to display the result in output string how can I convert that Input Stream to Sting? package com.venkattt.pack; import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; import java.net.SocketException; import org.ksoap2.SoapEnvelope; import org.ksoap2.serialization.SoapObject; import org.ksoap2.serialization.SoapPrimitive; import org.ksoap2.serialization.SoapSerializationEnvelope; import org

Getting specific file from ZipInputStream

橙三吉。 提交于 2019-12-23 08:02:50
问题 I can go through ZipInputStream , but before starting the iteration I want to get a specific file that I need during the iteration. How can I do that? ZipInputStream zin = new ZipInputStream(myInputStream) while ((entry = zin.getNextEntry()) != null) { println entry.getName() } 回答1: If the myInputStream you're working with comes from a real file on disk then you can simply use java.util.zip.ZipFile instead, which is backed by a RandomAccessFile and provides direct access to the zip entries by

Exception in thread “main” java.lang.NullPointerException at opennlp.tools.postag.POSTaggerME.train()

笑着哭i 提交于 2019-12-23 05:31:20
问题 There are same problem! I get InputSteram = null , I used IntelliJ IDEA, OpenNLP 1.9.1. on Ubuntu 18.04 public void makeDataTrainingModel() { model = null; System.out.println("POS model started"); //InputStream dataIn = null; InputStreamFactory dataIn = null; try { dataIn = new InputStreamFactory() { public InputStream createInputStream() throws IOException { return NLPClassifier.class.getResourceAsStream("/home/int/src /main/resources/en-pos.txt"); } }; //I get null pointer here in dataIn

How do I open a file located in WEB-INF?

一个人想着一个人 提交于 2019-12-23 04:28:08
问题 My servlet lets user upload a file, I've created a button to view the uploaded file. now, on click of that button I want the uploaded file to open. How do I do this on the JSP side or servlet.java side? it is located in WEB-INF/Uploads/my.txt folder. =====================================EDIT========================================= Based on answers below, I've modified my code and I'm pasting the same here for more answers, protected void doGet(HttpServletRequest request, HttpServletResponse