bufferedreader

java BufferedReader works on windows and not mac

僤鯓⒐⒋嵵緔 提交于 2020-02-28 07:21:45
问题 I am trying to read an output from a server using BufferedReader or Scanner but it gets stuck on read() or readLine() objects. It never returns from that line. However, it is working on Windows perfectly. The code to read the output is seen below: while ((serverResponce = this.in.readLine()) != null) { if (serverResponce.compareTo(message) == 0) { break; } } or using Scanner class: Scanner scanner = new Scanner(socket.getInputStream()); while (scanner.hasNextLine()) { serverResponce = scanner

Android Reading a large text efficiently in Java

泪湿孤枕 提交于 2020-02-25 04:13:28
问题 My code is too slow How can I make my code efficiently? Currently the code needs several minutes until the file was read, which is way too long. Can this be done faster? There is no stacktrace, because it works, but too slow. Thanks! The Problem Code: private void list(){ String strLine2=""; wwwdf2 = new StringBuffer(); InputStream fis2 = this.getResources().openRawResource(R.raw.list); BufferedReader br2 = new BufferedReader(new InputStreamReader(fis2)); if(fis2 != null) { try {

Loop through buffer content with different value

房东的猫 提交于 2020-01-25 07:41:05
问题 Need help, I am getting buffer data using plugin and matching iframe tag. After getting buffer value, I am retrieving iframe src and replacing them with blank src. When I loop the src values and output and using preg_replace it does not replace value according to loop and replace with the first iframe values... Here is my code add_action('wp_footer', 'scheck_iframe_value'); function scheck_iframe_value() { $get_me_buffers = ob_get_clean(); $pattern = '@(.*)(<iframe(?:.*?)</iframe>)(.*)@m'; ob

How do I close a file after catching an IOException in java?

这一生的挚爱 提交于 2020-01-21 04:41:05
问题 All, I am trying to ensure that a file I have open with BufferedReader is closed when I catch an IOException, but it appears as if my BufferedReader object is out of scope in the catch block. public static ArrayList readFiletoArrayList(String fileName, ArrayList fileArrayList) { fileArrayList.removeAll(fileArrayList); try { //open the file for reading BufferedReader fileIn = new BufferedReader(new FileReader(fileName)); // add line by line to array list, until end of file is reached // when

Reset buffer with BufferedReader in Java?

三世轮回 提交于 2020-01-18 04:44:10
问题 I am using class BufferedReader to read line by line in the buffer. When reading the last line in the buffer, I want to start reading from the beginning of the buffer again. I have read about the mark() and reset() , I am not sure its usage but I don't think they can help me out of this. Does anyone know how to start reading from the beginning of the buffer after reaching the last line? Like we can use seek(0) of the RandomAccessFile ? 回答1: mark/reset is what you want, however you can't

Closing Reader/Stream in Java [duplicate]

笑着哭i 提交于 2020-01-17 04:32:09
问题 This question already has an answer here : How can I fix an “IOException: Stream closed” exception using System.in? (1 answer) Closed 4 years ago . In my code I have to read user input from console: class Demo { //...some code public String readUserInput() throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); String userInput = reader.readLine(); reader.close(); return userInput; } } On first time when I use method readUserInput() on Demo object

Reading a text file then performing a character count and printing the relative frequency of each one

放肆的年华 提交于 2020-01-16 05:13:07
问题 I'm looking to perform a character count on a text file and then display each one with it's relative frequency to the rest of the characters, but I'm presently getting just blank console back. Any help would be greatly appreciated. import java.io.*; public class RelativeFrequency { public static void main(String[] args) throws IOException { File file1 = new File("Rf.txt"); BufferedReader in = new BufferedReader (new FileReader (file1)); System.out.println("Letter Frequency"); int nextChar;

how to work with Multidimensional arraylist?

陌路散爱 提交于 2020-01-15 22:50:38
问题 Hey guys sorry i'm a noob at java but im trying to make something and i need a multidimensional array list. It must be implemented into the following code: public static void OpenFile() { ArrayList<ArrayList<String>> array = new ArrayList<ArrayList<String>>(); int retrival = chooser.showOpenDialog(null); if (retrival == JFileChooser.APPROVE_OPTION) { try (BufferedReader br = new BufferedReader(new FileReader( chooser.getSelectedFile()))) { String sCurrentLine; while ((sCurrentLine = br

how to work with Multidimensional arraylist?

好久不见. 提交于 2020-01-15 22:50:06
问题 Hey guys sorry i'm a noob at java but im trying to make something and i need a multidimensional array list. It must be implemented into the following code: public static void OpenFile() { ArrayList<ArrayList<String>> array = new ArrayList<ArrayList<String>>(); int retrival = chooser.showOpenDialog(null); if (retrival == JFileChooser.APPROVE_OPTION) { try (BufferedReader br = new BufferedReader(new FileReader( chooser.getSelectedFile()))) { String sCurrentLine; while ((sCurrentLine = br

java file relative path in eclipse

回眸只為那壹抹淺笑 提交于 2020-01-14 04:25:07
问题 Three days i was trying to figure out how to read file using relative file path. In eclipse this compiles and works great, but when i export app. It says that it can't find the file. here is the screenshot and code i work on. This code works, but only in eclipse, it compiles and does job perfectly. But when i export it as as runnable jar file i get an error, that it cannot locate licenca.txt BufferedReader in = new BufferedReader(new FileReader(new File("licenca.txt").getPath())); String str;