text « API « Java I/O Q&A





1. Java BufferedReader back to the top of a text file?    stackoverflow.com

I currently have 2 BufferedReaders initialize on the same text file. When I'm done reading the reading the text file with the first BufferedReader, I use the second one to make ...

2. What is the best way to tokenize a text file in Java?    stackoverflow.com

What is the best way to tokenize a text file in Java, if

  1. I want to work with a java.io.Reader, not a String
  2. Delimiters should be returned?
I have evaluated the following classes:
  • java.util.StringTokenizer fulfills ...

3. Read text from InputStream    stackoverflow.com

If I start with a java.io.InputStream, what's the easiest way to read the entire stream out into a String (assuming utf-8)? This should be pretty easy but I'm mostly a C# person ...

4. Java: how to tell if a line in a text file was supposed to be blank?    stackoverflow.com

I'm working on a project in which I have to read in a Grammar file (breaking it up into my data structure), with the goal of being able to generate a ...

5. In Java, howd do I iterate through lines in a textfile from back to front    stackoverflow.com

Basically I need to take a text file such as :

Fred
Bernie
Henry
and be able to read them from the file in the order of ...

6. Sorting a text file by date - Date looks like DD/MM/YYYY    stackoverflow.com

I am trying to sort the dates from the earliest to the latest. I was thinking about using the bufferedreader and do a try searching the first 2 characters of the string ...

7. Java I/O: How to append to an already existing text file    stackoverflow.com

Hi I am having no problem writing to or appending to a file, the only problem is that as soon as I quit the program and then run it again, it ...

8. Trying to write a loop that uses an OutputStream to write to a text file    stackoverflow.com

I'm not a java programmer, I'm a VB programmer. I am doing this as part of an assignment, however, I'm not asking for help on something assignment related. I'd ...

9. Read data from a text file using Java    stackoverflow.com

I need to read a text file line by line using Java. I use available() method of FileInputStream to check and loop over the file. But while reading, the loop terminates ...





10. Import Textfile and read line by line in Java    stackoverflow.com

I was wondering how one would go about importing a text file. I want to import a file and then read it line by line. thanks!

11. Buffered Reader readLine() with Empty lines    stackoverflow.com

I am using buffered reader to grab a line at a time from a text file. I am trying to also get the line number from the text file using a ...

12. how to search for a certain word in a text file in java    stackoverflow.com

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 ...

13. how to update certain parts of text file in java    stackoverflow.com

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 ...

14. randomizing text file read in java    stackoverflow.com

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 ...

15. Writing data from different classes to a text file using BufferedWriter    stackoverflow.com

I am working with Java. I have created one text file. In that text file, I want one value to be stored in the text file from class1. Then I want ...

16. How to read odd number of lines from a text file using Java?    stackoverflow.com

I have a text file where each odd line holds an integer number (String ofcourse since its in a text file), even lines has a time. I only want to read ...





17. Read a line of text from an imput stream in Java, but keep the line-termination character(s)    stackoverflow.com

I have this code in Java:

InputStreamReader isr = new InputStreamReader(getInputStream());
BufferedReader ir = new BufferedReader(isr);
String line;
while ((line = ir.readLine()) != null) {
 //do stuff with "line"
}
If the input stream contains the following: ...

18. How to get QIODevice instance for stdin, stdout, stderr text streams in QtJambi?    stackoverflow.com

I would like to get QIODevice that represents standard IO streams (stdin, stdout, stderr) in QtJambi, so that i can get notified whenever a new line can be read or written. ...

19. Java BufferedReader arabic text file problem    stackoverflow.com

Problem: Arabic words in my text files read by java show as series of question marks : ?????? Here is the code:

        File[] fileList = ...

20. Reading lines of data from text files using java    stackoverflow.com

I have a text file with x amount of lines. each line holds a integer number. When the user clicks a button, an action is performed via actionlistener where it should ...

21. Are text files, pictures, sound files and video files all stored/transferred as stream of bytes?    stackoverflow.com

What else are represented as stream of bytes?

22. Buffered Reader text file?    stackoverflow.com

this is my first post on stack overflow! I'm new to Java and I've recently been experimenting with the Java Buffered Reader for File I/O. I'm getting an exception Exception in ...

23. InputStream Reader for text, newline deliminated input?    stackoverflow.com

Note: I am currently coding in java. I am looking to read input data into a string, one line at a time (or more), and i expect a lot of total ...

24. How to read certain lines from a textfile using Java?    stackoverflow.com

I have a text file that can store up to 3 lines (each line has time ##:##).

If the entire text file is empty : do task 1 ...

25. StringBuilders ending with mass nul characters    stackoverflow.com

I'm having a very difficult time debugging a problem with an application I've been building. The problem itself I cannot seem to reproduce with a representitive test program with the ...

26. NotePad not recognizing new line characters in java code using PrintStream to output to text file    stackoverflow.com

I need some help with my java project for school. Please see the code below for the classes Book and BookApplication, as well as the input text file and desired output ...

27. Java FileWriter - Append Line of Text File    stackoverflow.com

I have a button in a GUI, and when the button is pressed the user has the ability to add information to a text file. I have this part setup fine, ...

28. Quickest way to read text-file line by line in Java    stackoverflow.com

For log processing my application needs to read text files line by line. First I used the function readLine() of BufferedReader but I read on the internet that BufferedReader is slow when ...

29. Error whilst using StringTokenizer on text file with multiple lines    stackoverflow.com

I'm trying to read a text file and split the words individually using string tokenizer utility in java. The text file looks like this;

a 2000

4  
b 3000  
c 4000  ...

30. Why are the last few lines missing from a text file that I'm creating?    stackoverflow.com

I have a function that creates 7 different text files with rows of data. Those 7 files are then combined into a single file in a different function using the ...

31. Reading hebrew from text file with Java    stackoverflow.com

I'm having troubles with reading a UTF-8 encoded text file in Hebrew. I read all Hebrew characters successfully, except to two letters = '?' and '?'. Here is how I read it:

  ...

32. reading values from text file    stackoverflow.com

Please explain the compiler behaviour in the below code snippet. Consider the text file contains the following text TOBE and the corresponding byte values are 84, 79, 66, 69

for(int i=0;i<4;i++){
 ...

33. Problem with Java FileReader    stackoverflow.com

Hello I have this in my code

File file = new File("words.txt");
    Scanner scanFile = new Scanner(new FileReader(file));
    ArrayList<String> words = new ArrayList<String>();

    ...

34. Java - checking .txt for existing text across all lines    stackoverflow.com

Basically, I am looking to add to a .txt file depending on whether a certain line exist already or not. I.e. add the line to the .txt file if it doesn't exist ...

35. Java - delete line from text file by overwriting while reading it    stackoverflow.com

I'm trying to delete a line of text from a text file without copying to a temporary file. I am trying to do this by using a Printwriter and a Scanner ...

36. Read both text and binary data from InputStream    stackoverflow.com

I am trying to read data from a binary stream, portions of which should be parsed as UTF-8. Using the InputStream directly for the binary data and an InputStreamReader on top of ...

37. Java text file reading program with bufferedreader and FileReader. Compiling But not working    stackoverflow.com

This program is compiling though not working. It just handling the opening file exception. Please help me.Thanks for your time.

import java.io.*;
import java.util.Scanner;

public class ReadingFile {

    /**
   ...

38. What's the charset of text returned by InputStreamReader(InputStream in, Charset cs)    stackoverflow.com

I read a UTF-8 file by:

br = new BufferedReader(new InputStreamReader(new FileInputStream(filePath), Charset.forName("UTF-8")));
I would like to know what's the charset of returned String after I invoke br.readLine()? Eclipse on my Computer uses "GBK" ...

39. Java: How to add static text to file using ObjectOutputStream    stackoverflow.com

i am developing a small application in Java. At certain point i need to save the object of my custom class to a text file for this i override toString() method ...

40. Building/Running a Streaming Weka Text Classifer in Java    stackoverflow.com

We have been using the Weka Explorer GUI to build a few classifier models. Now Testing is complete we would like to implement this model within a Java application so it ...

41. Write int to text file using Writer    stackoverflow.com

Writer wr = new FileWriter("123.txt");
wr.write(123);
wr.close();
Output file contains:
{ Where is the problem? How to write int to text file using Writer?

42. Use junit to test reading from text and binary files and writing to text and binary files    stackoverflow.com

I wrote a Course class that has constructors that read from text and binary files and has methods to write to text and binary files. How do I write a junit ...

43. How to save text file without overwriting?    stackoverflow.com

I want to save in a text file without overwriting the current data. I mean the next data that will be save will go to the new/next line whenever I save ...

44. How to restore a text file?    stackoverflow.com

I want to restore the following data from the text file. The problem is only one string/line I can restore, I can't restore the rest of the data. Here's the code :

public ...

45. Inputstream reader skips over some text    stackoverflow.com

Hi guys so this is an exert from the code I have

public ItemList() throws Exception {
    //itemList = new List<Item>() ;
    List<Item> itemList = new ...

46. java efficient way to process big text files    stackoverflow.com

Im doing a frequency dictionary, in which i read 1000 files, each one with about 1000 lines. The approach i'm following is:

  • BufferedReader to read fileByFile
  • read the first file, get the first ...

47. How can I format the data written to a text file to be done in columns?    stackoverflow.com

Hi I have a bunch of data Im writing to a text file, each line of the rows holds about 4 different pieces of data, I want to make it so ...

48. I am having difficulties writing 5 number per line in a text file    stackoverflow.com

I have to write the 5 prime number per line until the computer writes the first 101 prime numbers. What do I have to do ...

49. Java text file size (before file is closed)    stackoverflow.com

I am collecting full HTML from a service that provides access to a very large collection of blogs and news websites. I am checking the HTML as it comes (in real-time) ...

50. Writing to text files in Java    stackoverflow.com

I have a method that writes a string to a text file using a DataOutputStream and the .writeBytes(String) method. If I write a string with a newline character, for example ...

51. Writing Readable Text to a File Using Streams    coderanch.com

I have a simple question about Java file i/o. I want to write strings to a file such that what is in the string is all that is written to the file. I've been using an ObjectOutputStream.writeUTF()/writeChars(), but doing so writes size information before each string or character, and the size information appears as nonsense characters when you open the file. ...

52. Using RandomAccessFile on text file    coderanch.com

Hi, I'm looking at using RandomAccessFile where I have a large (1.5GB) text file containing a regular grid of data. At the top of the file it tells you where the top left corner of the grid is (geographical X Y coordinates) and also the distance in metres between the regularly spaced data points (this is geographical data). There than follows ...

53. Reading a text file using BufferedReader.    coderanch.com

Suppose I have a text file that has these information "JavaRanch Big Moose 0.1 0.2 01 11 15 Hi|Bye JavaRanch Big Moose2 0.2 0.5 0.1 44 44 See you later|Come back" Each line is one record. I have nextRecod() query that returns the next record, and I implemented like this nextRecord() throws IOException{ bufReader = new BufferedReader(new FileReader(this.getDataFileName())); rec.readObject(bufReader); return new ...

55. Appending Objects to a textfile(using ObjectOutputStream)    coderanch.com

Hi I am pretty new to java and im having a problem with my program. My problem is appending objects to a file. When my program is first opened i can save books to the file and display them. However, when i exit and reopen the project i can only display objects previously added even after i save new objects to ...

56. FileWriter, makes new file but no text shows    coderanch.com

I am trying to create a text file and write to it, but I can't seem to get the text to post even though the file does get created. I have tried: FileWriter out = new FileWriter("fileOut", true ); as well as: BufferedWriter out = new BufferedWriter(new FileWriter("fileOut", true)); and then: out.write("string stuff" + numStuff); Any suggestions? -JS [ February 24, ...

57. Reading two text file using streamtokenizer    coderanch.com

Hi all, i have written a program to read a text file using streamtokenizer but there's some program when i compile and it says no source file but i have already put the text file into the folder together with the java program .Can anyone help me ? Here's the program : import java.io.*; import java.util.*; class TokenTest { public static ...

58. Creating a text file using FileWriter    coderanch.com

59. jav filewriter appending to text file at pos x    coderanch.com

Hello People, My problem is as follows ... I have used regex pattern and matcher to loop through a text file and write to another. When i use matcher.start and matcher.end it returns the matched pattern but when I try to append the new string at this position I want it is appended to the end of the text file only ...

60. Using BufferedReader and StringTokenizer to delete numericals in a text file    coderanch.com

Hi i was wondering: does anybody have an idea whether or not this is possible: I have a text file, of which i read the contents with BufferedReader and FileReader, with many trivia questions, which i got from someone i know. I am trying to write a trivia game with these questions. The problem is, the file looks as follows (i ...

61. how to get plain text in file using print stream    coderanch.com

Hai, i am facing problem with printstream.if i am giving html structure inside of printstream, I am getting as such what i am giving inside of printstream. Example program: FileOutputStream outfile=new FileOutputStream("d:\\temp\\Fn1.txt"); PrintStream p = new PrintStream( outfile); p.println( "

Test Output

" ); p.println( "" ); p.println( "
x1
" ); p.println( "
x2
" ); ..but i want result in a file like; Test Output ...

x2

62. Delete text when using RandomAccessFile    coderanch.com

64. Identify text vs. binary content in InputStream    coderanch.com

Have a webapp where I receive a file upload. Utilizing O'Reilly multipart tools to grab the file as follows: MultipartParser mParser = new MultipartParser(request, 1024 * 1024); Part part = null; while ((part = mParser.readNextPart()) != null) { if (part.isFile() == true) { FilePart fp = (FilePart) part; BufferedReader bufReader = new BufferedReader(new InputStreamReader( fp.getInputStream())); ... The idea is that the ...

66. FileReader cannot find text file!    coderanch.com

My program consistently says that it cannot find a text file I specify. Using both NetBeans and Eclipse, I had it show me the absolute path it's using, and put the txt file there. No effect. It's in the directory with bin and src directories. //blah blah blah, get main things going.. File appBase = new File("FindMe.txt"); //to determine current directory ...

67. Reading a text file using FileReader & BufferedReader : Unexpected output !    coderanch.com

the program below compiles properly. Its supposed to "print" the below source code saved inside "mytxt.txt" . But i get only some parts of the text in output. import java.io.*; class writing { public static void main(String args[ ]) { try { //make a 'file' object File file = new File("mytxt.txt"); //Get data from this file using a file reader. FileReader ...

68. writing text file to outputstream    coderanch.com

Hi, I have a text file that I want to read and write it to outputstream. For that I am using ByteArrayOutputStream. The text file should be read line by line and after each line a linebreak character should be inserted. How can I implement this. Also is there any other better way through which I can achieve the same. Attached ...

69. How do I return an input stream from a text file    forums.oracle.com

Yes you are quite correct and as someone posting in the New To Java forum you would need as much help as you can get. You were provided with a link to a huge resource full of help than can answer a lot of your questions. So instead of being snide perhaps you should be thankful!

70. Question regarding readLine for textfile    forums.oracle.com

71. BufferedReader text to BufferedWriter file    forums.oracle.com

72. BufferedReader Not Reading Text File    forums.oracle.com

I added what you suggested but I do not get any errors. It just stops. Actually it goes to the method that calls this one and exits. I had a JOptionPane in it also and it came up when trying to read the file. Yes, I do have the file there and can open and read the file with Notepad. I ...

73. writing to text file using randomaccessfile    forums.oracle.com

//reading here from text file line = input.readLine(); String subs = ""; //printing here whatever is coming from input file System.out.println("" + line ); //processing for comments of specific type containing * $Header and removing lines between /*......*/ try { subs = line.substring(0,11); if(subs.equals(" * $Header:")){ long n = input.getFilePointer(); System.out.println("Header matched:" + n); input.seek(n-line.length()-6); System.out.println("filepointer " + input.getFilePointer()); String b ...

74. Text File Reader    forums.oracle.com

I have to write a program reading a txt file. The file has 5 column's and a varying amount of rows. I have to read in the txt file, and group different information together at the end and print it out using println. I have no idea how to read in the data. The first and fourth columns are words and ...

75. BufferedWriter / BufferedReader issue - grabbed text is sometimes cut off    forums.oracle.com

You're writing "encrypted" data to the file, terminating each "line" with a newline sequence, and then trying to read each "line". Suppose the "encrypted" data has an embedded newline in it. When you invoke readLine, it will see the newline (the one in the data itself, not the one you added after the data), and treat that as the "line" of ...

76. Reading from a text file using BufferedReader    forums.oracle.com

I don't want to use Scanner because I want to find the largest number per line of the text file if I use Scanner i will not be able to detect if I already read the next line. It will just read the entire number without knowing what line am I reading

78. BufferedReader from text string    forums.oracle.com

You could pass a StringReader to the BufferedReader, instead of InputStreamReader, hence switch. The StringReader doesn't have a "readLine()" method, hence why still using BufferedReader and passing a StringReader. I'm not particularly well informed about this area though - not sure why you're using a DataInputStream either... could pass the FileInputStream to the InputStreamReader directly?

80. Print Formatted Text Using PrintStream?    forums.oracle.com

84. Jumbled text using PrintWriter    forums.oracle.com

Hi, I'm using an instance of PrintWriter to occassionally output text to a file, but the text ends up messy and jumbled up. Not on character level but text is not appended in a synchronous way. Things I outputted earlier gets overwritten and text written just before program termination ends up at the beginning of the file etc. I use print(...) ...

87. Keep carriage returns in text data when using a BufferedReader    forums.oracle.com

I have a java application that creates an XML document and out puts it to a byte() so I can send it to a .net application and convert the byte() in a dataset to be used in my app. For each attribute in the document creation there is a method to handle it's value. I have aclob field that contains text ...

88. using string tokenizer to separate items read in from text file    forums.oracle.com

public static void main(String args[]) { try { f = new File("C:/T/text.txt"); fis = new FileInputStream(f); BufferedReader d = new BufferedReader(new InputStreamReader(fis)); while(!(s = d.readLine()).equals("")) { StringTokenizer st = new StringTokenizer(s, " "); System.out.println("1 Token : " + st.nextToken() + " , 2 Token : " + st.nextToken()); } } catch(FileNotFoundException fnfe) { fnfe.printStackTrace(); } catch(IOException ioe) { ioe.printStackTrace(); }

89. Getting text from the clipboard as a stream    forums.oracle.com

Is there any way to get the (text) contents of the system clipboard as a stream? I want to be able to specify that a program gets its info from either a text file or the clipboard without having to save the clipboard using Notepad. The only references in the tutorials that I can find to the clipboard are for drag-and-drop. ...