bufferedreader

Output from Process.getInputStream() buffered too long

自古美人都是妖i 提交于 2019-12-24 22:10:04
问题 I have a Java program that uses Process Builder to start an external program. I have a Process Builder with the command, and I use the code below to get the program going. What I want to do is to print out the output just as the external program would have done, and I try to do this with the following code: pb.redirectErrorStream(true); p = pb.start(); InputStream is = p.getInputStream(); InputStreamReader isr = new inputStreamReader(is); BufferedReader br = new BufferedReader(isr, 32); while

Output from command prompt returning null

别来无恙 提交于 2019-12-24 09:41:07
问题 String line; String output = ""; Process p = Runtime.getRuntime().exec("cmd /c start cmd.exe /K \"cd c:/Windows/system32 && dir && netstat | Findstr \"ldap\"\""); BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream())); while ((line = input.readLine()) != null) { output += (line + '\n'); } System.out.println(output); input.close(); This code seems perfect for many,but for me input.readline just returns null.I guess because it has reached end of the console.How do

PrintWriter won't write

前提是你 提交于 2019-12-24 08:27:12
问题 I have the following problem. I programmed a simple Echo Server and Echo Client but the problem is that in the loop of the Server, where I read from the Buffered Reader, the programme stuck and it won't write. import java.net.*; import java.util.*; import java.io.*; public class SimpleServer { public static void main(String[] args) { System.out.println("Dies ist ein simpler Echo Server"); int port = 6000; try { ServerSocket server = new ServerSocket(port); //server.setSoTimeout(30000); System

Java BufferedReader action on character?

戏子无情 提交于 2019-12-24 07:10:05
问题 enter code here I'm reading a stream from a device in Linux which contains hexidecimal letters and is delimited by "^M". Whenever the device is ready for more information it sends the character ">". The stream looks like this: ^M^M01 02 F3^M00 01 F3 3E^M>" I need to detect the char > and perform an action on that char. Is there a way I can delimit on ">" and have that character read? Basically it currently looks like this 01 02 F3 00 01 F3 3E I need > to trigger a separate action. It does not

How to read a specified String from an input file, then read the next word after it

…衆ロ難τιáo~ 提交于 2019-12-24 03:27:37
问题 In Java I want to be able to have two JTextFields that take in String. One is a username and the other a password. to "login", the program will search through a file --> accounts.txt and will search first for "usrnm:", once it finds it, it takes the word right after the : the same goes for the password but it searches for "pswrd:". Here's what iv'e got so far: public void checkCredentials() { try { BufferedReader br = new BufferedReader(new FileReader(new File("accounts.txt"))); String text =

Java readLine() not working properly

北战南征 提交于 2019-12-24 03:12:42
问题 I'm writing a translator program that reads the translations from a text file. This method reads from the text file and adds it to a Map object that i'm using for the dictionary. public Map<String, String> loadTranslations() throws IOException { Map<String, String> translations = new HashMap<String, String>(); BufferedReader in = null; try { in = new BufferedReader(new FileReader(System.getProperty("user.dir") + "\\resource\\translations.txt")); englWord = in.readLine(); frenWord = in

Why I can't read /proc/net/xt_qtaguid/stats correctly by FileReader in Android ICS

对着背影说爱祢 提交于 2019-12-24 02:23:30
问题 I want to read /proc/net/xt_qtaguid/stats in Android ICS, which records all interfaces and applications traffic stats. following is the code snippet: String line = null; BufferReader reader = new BufferedReader(new FileReader(new File("/proc/net/xt_qtaguid/stats"))); line = reader.readLine();/*Here I can read the 1st line correctly, it return "idx iface acct_tag_hex..."*/ splitLine(line, keys); line = reader.readLine();//!!!!!Read next line, it returns null!!!!!! If I cat this file, it will

reading large lists through stdin in C

风流意气都作罢 提交于 2019-12-24 00:44:17
问题 If my program is going to have large lists of numbers passed in through stdin , what would be the most efficient way of reading this in? The input I'm going to be passing into the program is going to be of the following format: 3,5;6,7;8,9;11,4;; I need to process the input so that I can use the numbers between the colons (i.e I want to be able to use 3 and 5, 6 and 7 etc etc). The ;; indicates that it is the end of the line. I was thinking of using a buffered reader to read entire lines and

Java BufferedReader error with try block

不问归期 提交于 2019-12-24 00:14:58
问题 I have this method that is supposed to load a file but it is giving me this error: NamnMetod.java:175: error: unreported exception FileNotFoundException; must be caught or declared to be thrown BufferedReader inFil = new BufferedReader(new FileReader(fil)); ^ NamnMetod.java:177: error: unreported exception IOException; must be caught or declared to be thrown String rad = inFil.readLine(); ^ This is my code: public static void hämtaFrånText() { try { EventQueue.invokeAndWait(new Runnable() {

How to read plain text file in kotlin?

谁都会走 提交于 2019-12-23 16:52:18
问题 There may be various way to read plain text file in kotlin. I want know what are the possible ways and how I can use them. 回答1: Using BufferedReader import java.io.File import java.io.BufferedReader fun main(args: Array<String>) { val bufferedReader: BufferedReader = File("example.txt").bufferedReader() val inputString = bufferedReader.use { it.readText() } println(inputString) } Using InputStream Read By Line import java.io.File import java.io.InputStream fun main(args: Array<String>) { val