writing a text into text file at particular line number

writing a text into text file at particular line number

Hi,

thanks for quick response, I want to insert text at some particular line number..

after line number four my text will display in text file using java program

View Answers

February 22, 2012 at 5:31 PM

import java.io.*;

public class WriteAtSpecificLine {

        public static void main(String[] args) {
                String line = "";
                int lineNo;
                try {
                    File f=new File("c:/file.txt");
                        FileWriter fw = new FileWriter(f,true);
                        BufferedWriter bw = new BufferedWriter(fw);
                        LineNumberReader  lnr = new LineNumberReader(new FileReader(f));
                        lnr.setLineNumber(4);

                        for(int i=1;i<=lnr.getLineNumber();i++){
                        bw.newLine();
                        }
                        bw.write("Hello World");
                        bw.close();
                        lnr.close();
                        } catch (IOException e) {
                        e.printStackTrace();
                }
           }
}









Related Tutorials/Questions & Answers:
writing a text into text file at particular line number
writing a text into text file at particular line number   Hi, thanks for quick response, I want to insert text at some particular line number.. after line number four my text will display in text file using java program
writing a text into text file at particular line number
writing a text into text file at particular line number   Hi, thanks for quick response, I want to insert text at some particular line number.. after line number four my text will display in text file using java program  
Advertisements
writing a text into text file at particular line number
writing a text into text file at particular line number   Hi, thanks for quick response, I want to insert text at some particular line number.. after line number four my text will display in text file using java program  
Map words to line number in text file and show occurence
Map words to line number in text file and show occurence  hi i want to Map words to line number in text file and show occurrence of word in java coding
Write Text To File In New Line.
Write Text To File In New Line. In this tutorial you will learn how to write text into file in a new line. When you are writing in a file you may be required to finish the line and want to write the other text in a new line
How to write file text In New Line
you went new text in new line. For this we created a new text file named... to write file text in New line in Java...How to write file text In New Line  Hi friends, How to write file
dynamically writing text javascript
dynamically writing text javascript  dynamically writing text javascript. Is it possible
dynamically writing text javascript
dynamically writing text javascript  dynamically writing text javascript. Is it possible
How to read a large text file line by line in java?
How to read a large text file line by line in java?  I have been... memory assigned is also a limit. So, we have decided to read the text file line... you kind advice and let's know how to read a large text file line by line in java
Problem while using a HashMap for writing text ina RTF file. - Framework
Problem while using a HashMap for writing text ina RTF file.  Hi, I am trying to generate a RTF file using iText.jar, wherein I am taking... matched to the string then only write to the RTF file. Problem is Document writes
How to extract a specific line from a text file? - IoC
How to extract a specific line from a text file?  Hi all, i'm trying to write a code that return a specific line from a text file. so my first...° 100 to 120 for example. My Text file contain numbers and words. How i have
text file
text file  Hello can I modify the program below so that all the numerical data is stored in an external text file,that is the data contained in the array list.Thank you! mport java.util.*; import java.text.*; import
text file
text file  Hi can you help me I have to modify the program below so that all the data held in it is stored in an external text file.So there should... at the start of the program from a seperate external text file.Thank you! mport
Sorting text file
Sorting text file  Hello friends, i'm writing search page for my local website. i'm storing all file list in text file. And also adding a value to each line at the beginning. now i want to sort file content in descending order
Reading a text file in java
Reading a text file in java  What is the code for Reading a text file... in java.io.* package for reading and writing to a file in Java. To learn more about reading text file in Java see the tutorial Read File in Java. Thanks
Read text file in PySpark
Read text file in PySpark - How to read a text file in PySpark? The PySpark... text file and then collect the data into RDD. The term RDD stands... will create a text file with following text:ADS_TO_REPLACE_2 one two three
inserting text into text file using java application
inserting text into text file using java application  Hi, I want to insert a text or string into a text file using java application
Adding text in to text area of jframe at new line with different background colour
Adding text in to text area of jframe at new line with different background colour  Hi, I am reading text from text file and i want to write that text in to text area of jframe.But i am reading line by line from file and i want
line number in a file of entered string
line number in a file of entered string  when i entered string from console , it should show line number in a file of that string
Read text File
Read text File  Hi,How can I get line and keep in a String in Java
how to update the text file?
how to update the text file?  if my text file contains a string and integer in each line say,: aaa 200 bbb 500 ccc 400 i need a java code to update the integer value if my input String matches with the string in file. please
Java read text file
a text file one line at a time. It can also be used to read large text files... the text file one line at a time. As it is not thread safe. Code must... text file in Java?": ADS_TO_REPLACE_3 Example of Read text File Line
Java file new line
Java file new line In this section, you will learn how to write the text in new line of text file. Description of code: The package java.io.* has provide... a text in the file, there are different output streams. Among them
uploading a text file into a database
uploading a text file into a database  how to upload a text file... { static File file; public static void main(String[] args) throws Exception { JLabel label=new JLabel("Choose File
ModuleNotFoundError: No module named 'recognizers-text-number'
ModuleNotFoundError: No module named 'recognizers-text-number'  Hi...: No module named 'recognizers-text-number' How to remove the ModuleNotFoundError: No module named 'recognizers-text-number' error? Thanks   
ModuleNotFoundError: No module named 'recognizers-text-number-with-unit'
ModuleNotFoundError: No module named 'recognizers-text-number-with-unit' ...: ModuleNotFoundError: No module named 'recognizers-text-number-with-unit' How to remove the ModuleNotFoundError: No module named 'recognizers-text-number-with-unit'
Convert Text File to PDF file
Convert Text File to PDF file  Here is the way how to covert your Text file to PDF File, public class TextFileToPDF { private static void...(inLine); System.out.println("Text is inserted into pdf file
how to update the text file?
how to update the text file?  my textfile with name list.txt: Rice... i want to update the quantity in my text file, if the item i entered matches...=new float[n1]; for(int i=0;i File file ; FileReader fr=null
Convert Text File to PDF file
Convert Text File to PDF file  import java.io.BufferedReader; import...); System.out.println("Text is inserted into pdf file"); document.close... FileReader( Input File)); String inLine = null
save text file - Java Beginners
save text file  hi i have just start programming in java.please guide me if i want to read a text file in java.then the text file is save in which directory
Text field save as word file
Text field save as word file  Dear experts At run how to save set of text field contains text into single Word file. To save in our desktop computer. Solve my problem
Creating a log in a text file - Applet
time it is run. I have figured of a way of writing the time to a text file using... as an application. Therefore i have added it onto a frame. I need to create a text file..."); Label label1 = new Label("Enter the file name:"); TextField text = new
Adding a text file - Java Beginners
Adding a text file  Hello, I need a program that will search a text file of strings representing numbers of type int and will write the largest and the smallest numbers to the screen. The file contains nothing but strings
Converting Text Files into Bzip File
Converting Text Files into Bzip File  Hi, I am facing the problem during run the program, when converting text files into Bzip file. Please guide me how do i convert the text file into bzip file in PHP. I will welcome, if anyone
Write Text into File
Write Text into File       In this example we are writing text into file.In... to write text into file. At last close output file using close() method.ADS
Read Lines from text file
line based on a predefined size... Eg : If the 1st line of the text file... need to do this for a file with 11 lines. Here's my code while((line... read from the text file and displays the output as desired. Unable to read the rest
Reading Text file and storing in map
Reading Text file and storing in map  Hi I have multiple text files. I want to read thoses files and store those records in map. Map will be of "LinkedHashMap<String, Map<String, String>>" type. Please let me know
Steps to read text file in pyspark
Steps to read text file in pyspark  Hi, I am learning to write program in PySpark. I want to simply read a text file in Pyspark and then try some code. What are the Steps to read text file in pyspark? How much time it takes
How to read file in java
and writing operations with a file. In this section you will learn how to read a text file line by line  in java. FileInputStream- This class reads bytes from... program  use DataInputStream for reading text file line by line
how to convert image file to text file?
how to convert image file to text file?  hi, can anybody tell how to convert image file to text file? plz help me
Layout text along a line using LineMetrics
Layout text along a line using LineMetrics... to layout text along a line. For this, class LineMetrics is used which layouts the text along a line. The Font class represents the font. The class
Read Specific Line from file Using Java
Read Specific Line from file Using Java Here we are going to read a specific line from the text file. For this we have created a for loop to read lines 1 to 10 from the text file. If the loop reached fifth line, the br.readLine() method
Search and return lines of text file
Search and return lines of text file  I wrote the following code, that found lines of txt file with contains certain word, but it returns only the first or the last line! (However, the System.out.println show me all the lines
a jsp code for creating a text file
a jsp code for creating a text file  Hello,i need jsp code for creating a new text file for each user, when they login in to the website for creating a new data file. So i need a jsp code for following options. when user login
JavaScript write to text file
JavaScript write to text file  ... are going to create a file and write text into it using JavaScript. In the given example... to write the text into the created file, we have used WriteLine() method. This code
Count lines of a particular file
In this program you will learn how to read a file and count number of lines in it. This is the simple program that opens a file and read one line at a time... provides many API's for reading, writing, updating and deleting the file. You
stand alone program for text file editing
stand alone program for text file editing  steps 1.read a text file origi.txt from a location 2.make a copy of the text file to the same location with name as origi_copy.txt(example) 3.each line of the copy should start from 10
Break a Line for text layout
Break a Line for text layout   ... to break a line. To break down the text into lines, the class LineBreakMeasurer... in the constructor of class AttributedString which holds the text. To allows iteration
How to extract the entire line with specific data from a Text in java?
How to extract the entire line with specific data from a Text in java? ... to extract only lines with number like 001 or 002 , every line with a number like in the example but not lines without number. The text content 500 lines but some
How to append text to an existing file in Java
How to append text to an existing file in Java  How to append text to an existing file in Java

Ads