bufferedreader

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

Buffered Reader read text until character

坚强是说给别人听的谎言 提交于 2019-12-23 13:01:28
问题 I am using a buffered reader to read in a file filled with lines of information. Some of the longer lines of text extend to be more than one line so the buffered views them as a new line. Each line ends with ';' symbol. So I was wondering if there was a way to make the buffered reader read a line until it reaches the ';' then return the whole line as a string. Here a how I am using the buffered reader so far. String currentLine; while((currentLine = reader.readLine()) != null) { // trim

wrong usage of BufferedReader

只愿长相守 提交于 2019-12-23 09:31:05
问题 s=new Scanner(new BufferedReader(new InputStreamReader(this.clientSocket.getInputStream()))); while(s.hasNext()){ System.out.println("Am intrat in bucla s:"); longitude=Integer.parseInt(s.next()); System.out.println("Valoare longitudine:"+longitude); latitude=Integer.parseInt(s.next()); System.out.println(latitude); I'm using the lines above to read some data from a client-server connection;this is the server side.The data are read in scanner s and after that I try to display it,but when I

Java BufferedReader check next lines of a loop before looping

风格不统一 提交于 2019-12-23 08:29:32
问题 I'm parsing a .cvs file. For each line of the cvs, I create an object with the parsed values, and put them into a set. Before putting the object in the map and looping to the next, I need to check if the next cvs's line is the same object as the actual, but with a particular property value different. For that, I need check the next lines of the buffer, but keep the loop's buffer in the same position. For example: BufferedReader input = new BufferedReader(new InputStreamReader(new

Java Cannot Read From File

馋奶兔 提交于 2019-12-23 05:14:23
问题 I am writing a Java program that can take user entries and save them into an ArrayList, then use the ArrayList to open a series of webpages. The program should also be able to read in web addresses from a file. This is where I'm having issues. I'm currently gettting: The file bills.txt was not found. //the file is in my src folder Exception in thread "main" java.lang.NullPointerException at PayBills.main(PayBills.java:92) //this is when the BufferdReader is closed This isn't homework but the

Unhandled exception: FileNotFoundException

你。 提交于 2019-12-22 19:00:13
问题 I have some problems reading file in java: my file is for example: 3,4 2 6 4 1 7 3 8 9 where first line 3 and 4 are the lenght of array A and B and then the element of each array. I made this import java.io.*; import java.util.Arrays; public class Progetto { public static void main(String args[]) { // Open the file that is the first // command line parameter FileInputStream fstream = new FileInputStream("prova.txt"); BufferedReader br = new BufferedReader(new InputStreamReader(fstream));

How to clear/reset/open an input stream so it can be used in 2 different methods in Java?

送分小仙女□ 提交于 2019-12-22 13:07:15
问题 Here's the code: package testpack; import java.io.*; public class InputStreamReadDemo { private void readByte() throws IOException { System.out.print("Enter the byte of data that you want to be read: "); int a = System.in.read(); System.out.println("The first byte of data that you inputted corresponds to the binary value "+Integer.toBinaryString(a)+" and to the integer value "+a+"."); // tried writing System.in.close(); and System.in.reset(); } private void readLine() throws IOException {

BufferedReader readLine used in while loop

点点圈 提交于 2019-12-22 11:36:36
问题 I have seen BufferedReader using while loops to iterate through the contents of a file, with code more or less like: try { FileReader fr = new FileReader(file); Buffered Reader br = new BufferedReader(fr); String line; while ( (line = br.readLine()) != null ) { // do something } } catch () {} what I don't understand is how the while loop is internally incrementing its counter until it has read all lines in the document. To me, the while loop above means "if the first line (line[0]) is not

Convert `BufferedReader` to `Stream<String>` in a parallel way

∥☆過路亽.° 提交于 2019-12-22 05:10:44
问题 Is there a way to receive a Stream<String> stream out of a BufferedReader reader such that each string in stream represents one line of reader with the additional condition that stream is provided directly (before reader read everything)? I want to process the data of stream parallel to getting them from reader to save time. Edit: I want to process the data parallel to reading. I don't want to process different lines parallel. They should be processed in order. Let's make an example on how I

How is the best way to extract the entire content from a BufferedReader object in Java?

孤者浪人 提交于 2019-12-21 04:39:25
问题 i'm trying to get an entire WebPage through a URLConnection. What's the most efficient way to do this? I'm doing this already: URL url = new URL("http://www.google.com/"); URLConnection connection; connection = url.openConnection(); InputStream in = connection.getInputStream(); BufferedReader bf = new BufferedReader(new InputStreamReader(in)); StringBuffer html = new StringBuffer(); String line = bf.readLine(); while(line!=null){ html.append(line); line = bf.readLine(); } bf.close(); html has