bufferedreader

Java using scanner enter key pressed

南笙酒味 提交于 2019-11-26 10:01:32
问题 I am programming using Java. I am trying write code which can recognize if the user presses the enter key in a console based program. How can I do this using java. I have been told that this can be done using either Scanner or, buffered input reader. I do not understand(or know how to use) buffered input reader. I tried to do do this using scanner but after pressing enter twice the program terminates, and it doesn\'t work Scanner readinput = new Scanner(System.in); String enterkey = \"Hola\";

Read special characters in java with BufferedReader [duplicate]

江枫思渺然 提交于 2019-11-26 09:55:25
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Read/write .txt file with special characters Im reading a file but I dont know how to read the accents and special caracters, here is mo code for read I read I have to add a different codification but i dont know how to doit File file = new File(\"C://fichero.csv\"); BufferedReader bufRdr = new BufferedReader(new FileReader(file)); String line = null; line = bufRdr.readLine(); Thanks 回答1: Try with the following:

Using BufferedReader.readLine() in a while loop properly

我的梦境 提交于 2019-11-26 09:45:28
问题 So I\'m having an issue reading a text file into my program. Here is the code: try{ InputStream fis=new FileInputStream(targetsFile); BufferedReader br=new BufferedReader(new InputStreamReader(fis)); //while(br.readLine()!=null){ for(int i=0;i<100;i++){ String[] words=br.readLine().split(\" \"); int targetX=Integer.parseInt(words[0]); int targetY=Integer.parseInt(words[1]); int targetW=Integer.parseInt(words[2]); int targetH=Integer.parseInt(words[3]); int targetHits=Integer.parseInt(words[4]

Specific difference between bufferedreader and filereader

一笑奈何 提交于 2019-11-26 06:56:54
问题 I would like to know the specific difference between BufferedReader and FileReader . I do know that BufferedReader is much more efficient as opposed to FileReader , but can someone please explain why (specifically and in detail)? Thanks. 回答1: In simple manner: A FileReader class is a general tool to read in characters from a File. The BufferedReader class can wrap around Readers, like FileReader, to buffer the input and improve efficiency. So you wouldn't use one over the other, but both at

Android Reading from an Input stream efficiently

与世无争的帅哥 提交于 2019-11-26 05:57:17
问题 I am making an HTTP get request to a website for an android application I am making. I am using a DefaultHttpClient and using HttpGet to issue the request. I get the entity response and from this obtain an InputStream object for getting the html of the page. I then cycle through the reply doing as follows: BufferedReader r = new BufferedReader(new InputStreamReader(inputStream)); String x = \"\"; x = r.readLine(); String total = \"\"; while(x!= null){ total += x; x = r.readLine(); } However

Run .exe file in Java from file location

限于喜欢 提交于 2019-11-26 04:49:16
问题 I have to open a .exe file from my Java program. So I tried following code First. Process process = runtime.exec(\"c:\\\\program files\\\\test\\\\test.exe\"); But I was getting some error. Then I found out that the exe has to be launched from that location that is c://program files/test/ only then it will open with out errors. So I decided to write a .bat file and execute so that it will cd to that location and execute the .exe file. Following is my code: BufferedWriter fileOut; String

Do I need to close() both FileReader and BufferedReader?

半城伤御伤魂 提交于 2019-11-26 02:29:32
问题 I\'m reading a local file using a BufferedReader wrapped around a FileReader: BufferedReader reader = new BufferedReader(new FileReader(fileName)); // read the file // (error handling snipped) reader.close(); Do I need to close() the FileReader as well, or will the wrapper handle that? I\'ve seen code where people do something like this: FileReader fReader = new FileReader(fileName); BufferedReader bReader = new BufferedReader(fReader); // read the file // (error handling snipped) bReader

Scanner vs. BufferedReader

半世苍凉 提交于 2019-11-25 23:59:13
问题 As far I know, the two most common methods of reading character-based data from a file in Java is using Scanner or BufferedReader . I also know that the BufferedReader read files efficiently by using a buffer to avoid physical disk operations. My questions are: Does Scanner performs as well as BufferedReader ? Why would you choose Scanner over BufferedReader or vice versa? 回答1: Scanner is used for parsing tokens from the contents of the stream while BufferedReader just reads the stream and