Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners writing a text into text file at particular line number

Have Programming Question? Ask it here!
 
 
 


mazeed
writing a text into text file at particular line number
1 Answer(s)      2 years and 6 months ago
Posted in : Java Beginners


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


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


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
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
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
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
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
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
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
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
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
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... write() adds the simple text to the file. Then the nextLine() writes a line
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
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
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
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
how to update the text file?
how to update the text file?  my textfile with name list.txt: Rice... in my text file, if the item i entered matches with item in text file.how can i...]; for(int i=0;i File file ; FileReader fr=null ; FileWriter
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
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
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
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
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
How to read file in java
and writing operations with a file. In this section you will learn how to read a text...; use DataInputStream for reading text file line by line with a BufferedReader...-independent way.  BufferedReader-This class read the text from a file line
Count lines of a particular file
) { try{ System.out.println("Getting line number of a paritcular file..._package>java NumberOfLine Getting line number of a paritcular file example...In this program you will learn how to read a file and count number of lines
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
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
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
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
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
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
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
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
Java Read File Line by Line - Java Tutorial
Java Read File Line by Line - Example code of reading the text file... class to Read text File Line by Line. Our example program is reading a text... tutorial that explains you how to read a text file in Java one line at a time
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
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
Java file line reader
Java file line reader In this section, you will learn how to read a particular line from file. Sometimes you want to read a particular line from the file... and parse the file path. Through the code, we want to read the line 3 of the file
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
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
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
Java Write To File End Of Line
Java Write To File End Of Line In this tutorial you will learn how to write to file at the end of the line. Write to a file in which some contents are available already and you need to write the text at the end of line you may to use
Java search text file
Java search text file In this tutorial, you will learn how to search a text file in the current directory. For this, we have prompt the user to enter the name of a text file to search for. If the name does not have a .txt extension
Advertisements
 

 

 

DMCA.com