writing a text into text file at particular line number

Ads
 

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:30 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();
                }
           }
}

Ads









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
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
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
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
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
Read text file in PySpark
to read a text file in RDD and then print data line by line? We have large number...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
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
Java read text file
a text file one line at a time. It can also be used to read large text files...;: Example of Read text File Line by Line: import java.io.*; class FileRead...In the section we are discussing about how to read file line by line. Here we
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
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
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
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
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
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
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
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'
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
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
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
Line by Line reading from a file using Scanner Class
In this section, you will get to know about reading line by line a text file using java.util.Scanner class
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
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

Ads