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

mazeed
writing a text into text file at particular line number
1 Answer(s)      a year and 3 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

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 Pages:
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
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
Count lines of a particular file
_package>java NumberOfLine Getting line number of a paritcular file example! Please enter file name with extension: AddTwoBigNumbers.shtml Total line no: 58 Download this example
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
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
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
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
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
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 write to file line by line
Java write to file line by line In this section, you will learn how to write a file line by line. It is better to use Writer class instead of OutputStream class if you want to output text to the file since the purpose of Writer classes
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
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 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
Java Read File Line by Line - Java Tutorial
will use the DataInputStream class to Read text File Line by Line. Class... program to Read text File Line by Line... Java Read File Line by Line - Java Tutorial
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
Writing and Reading A File
into the text file. import java.io.*; import java.util.*; import javax.swing.*; import...;To extract the data from text file and save it to jtable, visit the following links...Writing and Reading A File  Hello, I've been trying to learn writing
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
file share to particular user
file share to particular user  hi i am doing my project in jsp-servlet.i am able to upload successfully any file to oracle database. i want to share a file to specific user , how to write code plzzz help. thank you in advance
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
Open Source Text Editor
Open Source Text Editor jEdit Programmers text editor jEdit is a mature and well-designed programmer's text editor with over 9 years....  FCKeditor - The text editor for Internet This HTML text
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
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
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
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
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
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
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
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
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
Java read file line by line
are going to read a file line by line. For reading text from a file it's better... class is used to read text from a file line by line using it's readLine method...Java read file line by line In this section, you will learn how to read a file
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...: The another program  use DataInputStream for reading text file line by line
gradient text, text effect, text
to take a new file with black background as here. Write Text: Select Horizontal... How to make a gradient text       We can make many different type of text by the help
Delete specific lines from text in Java
Delete specific lines from text in Java  Hi, beginning in java, i'm trying to delete specific line from a text file. Ex: i want to delete data between line 10 and 20 and between line 20 and 30. or i want to specify line
java write to a specific line
at specific line in text file. Java provides java.io package to perform file operations. Here, we are going to write the text to the specific line of the text... of line numbers. It seek to the desired position in the file using the method
How to Read a file line by line using BufferedReader?
How to Read a file line by line using BufferedReader?  Hello Java... to Read a file line by line using BufferedReader, efficiently and using less memory... java.io.BufferedReader in your program and use the class for reading the file 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 read text file in Servlets
it to the BufferedReader. A variable text is defined of String type. Read the file line... How to read text file in Servlets  ... file in servlets. In this example we will use the input stream to read the text
Text Area
Text Area  how to browse an image in text area instead of giving url of particular image
How to format text file? - Java Beginners
How to format text file?  I want the answer for following Query ***(Java code) How to open,read and format text file(notepad) or MS-word.../example/java/io/java-read-file-line-by-line.shtml Thanks
read text file and store the data in mysql - JDBC
read text file and store the data in mysql  when we store the data in mysql table from text file its store the data from new line to new column. how to store the data in different column from a single line of text file
Count characters from text file in Java
Count characters from text file in Java  At the "Count chracters fro mtext file in Java". I tried to run the code, but the error at the line have the directory of the text file ("C:\text.txt"). I use Eclipse to run this code. I
Text Editor Extensions
editors with some extra capabilities for filtering the text using command line.... This is useful for embedding base64 encoded text in a .properties file, running... Text Editor Extensions

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.

Tutorial Topics