bufferedreader

Java: Using the Scanner class to read input from a file without pipeing.

I currently have an implementation of a program where I read in the input using the Scanner class. Integer by integer. I do this by piping the input file via the command line. java program < input.txt I need to avoid piping the input by using an argument on the command line to open the file in my program. java program --file=in...

how to search for a certain word in a text file in java

how to search for a certain word in a text file in java? Using buffered reader, I have this code, but I get a java.lang.ArrayIndexOutOfBoundsException Please help me determine what's wrong with my program. System.out.println("Input name: "); String tmp_name=input.nextLine(); try{ FileReader fr; fr ...

how to bubble sort through a text file in java

How do I properly bubble sort through a text file by assigning the values to an array. In the code below I tried to assign the values from the text file to a string while there is still something to fetch. Then I used a for loop to assign the one that I have fetch to the array. Then tried to use the bubble sort to hopefully sort the numb...

how to update certain parts of text file in java

I want to be able to update a certain line on a text file. But I get the error that it cannot delete the file, why do I get this error? public class Main { public static void main(String[] args) { Main rlf = new Main(); rlf.removeLineFromFile("F:\\text.txt", "bbb"); } public void removeLineFromFile(String fi...

Java: Outputting text file to Console

I'm attempting to output a text file to the console with Java. I was wondering what is the most efficient way of doing so? I've researched several methods however, it's difficult to discern which is the least performance impacted solution. Outputting a text file to the console would involve reading in each line in the file, then writi...

randomizing text file read in java

I am trying to read a text file in java, basically a set of questions. With 4 choices and 1 answer. The structure looks like this: question option a option b option c option d answer I have no trouble reading it that way: public class rar{ public static String[] q=new String[50]; public static String[] a=n...

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

Hello everybody, 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 Buffere...

Java filereader bufferedreader printing out a certain number of lines

I am trying to use a file reader and buffered reader in java to print a certain a certain number of lines from a txt file. The file has over 100000 lines, but i just want to print the first 100. The code i have come up with looks like this: public class main { public static void main(String args[]) throws Exception { FileRe...

Reading a file into a multidimensional array

I want to read in a grid of numbers (n*n) from a file and copy them into a multidimensional array, one int at a time. I have the code to read in the file and print it out, but dont know how to take each int. I think i need to splitstring method and a blank delimiter "" in order to take every charcter, but after that im not sure. I would ...

Restriction on readLine()

Hello All, I just wanted to know if there is any restriction on the number of lines readLine method can read from a file in java.Any help will be grately appreciated.This is what I am talking about: FileReader fr1=new FileReader("/homes/output_train_2000.txt"); BufferedReader br1=new BufferedReader(fr1); while((line1=br1.readLine())!=n...