jaVA INT

jaVA INT

Read a text file and precede the line with the line number and write it to another new text file.

For example if you create a file Source.txt which has the following contents: Hello there I am supposed to have line numbers preceding me. Is it there ?

shall be written to Destination.txt as: 1. Hello there 2. I am supposed to have line numbers preceding me. 3. Is it there?

View Answers

December 15, 2010 at 4:45 PM

Hi Friend,

Try the following code:

import java.io.*;
class FileExample{

    public static void main(String[] args)throws Exception{
        BufferedWriter bw=new BufferedWriter(new FileWriter("C:/destination.txt",true));
        LineNumberReader ln = new LineNumberReader(new FileReader(new File("C:/hello.txt")));
        String line = "";
        while ((line = ln.readLine()) != null){
        System.out.println("Line:  " + ln. getLineNumber() + ": " + line);
        bw.write("Line:  " + ln. getLineNumber() + ": " + line);
        bw.newLine();
      }
      bw.close();

    }
}

Thanks









Related Tutorials/Questions & Answers:
jaVA INT
jaVA INT  Read a text file and precede the line with the line number and write it to another new text file. For example if you create a file Source.txt which has the following contents: Hello there I am supposed to have line
int to byte in java
int to byte in java  How to convert int to byte in Java?   int i =132; byte b =(byte)i; System.out.println(b);   public static byte[] intToByteArray(int value) { byte[] b = new byte[4
Advertisements
How to convert String to int in Java
into the int variable. How to convert String to int in Java? Thanks   Hi, In Java you can convert String to in with the help of following two functions...How to convert String to int in Java  Hi, I have String with int
How to convert String to int in Java
into the int variable. How to convert String to int in Java? Thanks   Hi, In Java you can convert String to in with the help of following two functions...How to convert String to int in Java  Hi, I have String with int
How to convert String to int in Java
into the int variable. How to convert String to int in Java? Thanks   Hi, In Java you can convert String to in with the help of following two functions...How to convert String to int in Java  Hi, I have String with int
How to convert String to int in Java
into the int variable. How to convert String to int in Java? Thanks   Hi, In Java you can convert String to in with the help of following two functions...How to convert String to int in Java  Hi, I have String with int
How to rewind the int buffer in java.
How to rewind the int buffer in java. In this tutorial, we will discuss how to rewind the int buffer in java.  IntBuffer API... static IntBuffer allocate( int capacity)  The allocate() method
How to clear int buffer in java.
How to clear int buffer in java. In this tutorial, we will discuss how to clear int buffer in java.          ...;} } Output C:\>java IntBufferClear Int value in the buffer. 22
java.lang.String.valueOf(int inum)
The valueOf(int inum) method in Java used for converting int value into string. Basically, inum converts the int value into a String. See the example below...) { String Str = String.valueOf(555); // int values
Java arraylist int
. In this example int data type gets converted into Integer data type. Example of Java Arraylist int import java.util.ArrayList; import java.util.List... arraylist can contain int data type elements also.  Only
How to allocate a new int buffer in java.
How to allocate a new int buffer in java.  In this tutorial, we will see how to allocate a new int buffer. IntBuffer API: The java.nio.IntBuffer... IntBuffer allocate( int capacity)  The allocate() method allocate
one attribute of type int - Java Beginners
one attribute of type int  hi friends can anyone help me understand this question:- Define a class called Month. Your class will have one attribute of type int to represent a month (1 for January, 2 for February, and so
String substring(int beginIndex, int endIndex)
the substring(int beginIndex, int endIndex) method through the following java program... String substring(int beginIndex, int endIndex)  ... explanation about the substring(int beginIndex, int endIndex) method of String
How to convert excel file int xml format in java
How to convert excel file int xml format in java  How to read excel file(xls) which is stored in any directory(D://) and convert it into xml format in java and place in any directory(E://).Can any body provide the code
Java char to int
Java char to int We are going to describe How to convert char to int. First... char to int. If we parse the string value it will display a single integer...); String s = character.toString(); int i = Integer.parseInt(s
Java Parse int Exception
Java Parse int Exception     ... Used in parseInt(java lang.String,int )method are ADS_TO_REPLACE_1 1) s- Stand... java.lang.integer.public static method int parseInt(String s) gives you NumberFormatException
Int and Bint
Int and Bint   hello, What is different between int and bint?   hii,ADS_TO_REPLACE_1 nice Question bigint can hold values from -2... but in case of intADS_TO_REPLACE_3 int can hold values from -2(race to the power)31
How to read all value from int buffer in java.
How to read all value from int buffer in java. In this tutorial, we will discuss how to read all value from int buffer in java.  IntBuffer API... Description static IntBuffer allocate( int capacity) 
The int keyword
; The int is a keyword in java that is used to define 32-bit signed integer... specific meaning relevant to a compiler. The keyword int in java programming language... of integer type. The java.lang.Integer class in java programming language wraps a int
range of int in c
range of int in c  What is the range of int in c/c++ and Java programming language
where is the definition of keywords like this, int, void present in Java ? e.g the definition of methods are in API.
where is the definition of keywords like this, int, void present in Java ? e.g the definition of methods are in API.  where is the definition of keywords like this, int, void present in Java ? e.g the definition of methods
How to convert a String to an int?
format. Now I want to convert into int value. Tell me How to convert a String to an int? Thanks   Hi, In Java its very easy and you can use...How to convert a String to an int?  I my program I am taking
String lastIndexOf(int ch)
about the lastIndexOf(int ch) method through the following java program... String lastIndexOf(int ch)     ... the lastIndexOf(int ch) method of String class. We are going to use lastIndexOf(int
Create a int array with the help of int buffer.
;} } Output C:\>java IntBufferArray Int value in buffer...Create a int array with the help of int buffer.  In this tutorial, we will see how to create a int array with the help of int buffer. IntBuffer API
Transfer the content of a int array into int buffer.
Transfer the content of a int array into int buffer.  In this tutorial, we will see how to transfer the content of a int array into int buffer... Method Description static IntBuffer allocate(int capacity
String copyValueOf(char[] data, int offset, int count)
String copyValueOf(char[] data, int offset, int count...[] data, int offset, int count) method of String class in Java... StrCopyValueOf.java C:\unique>java StrCopyValueOf The new String
ModuleNotFoundError: No module named 'int'
ModuleNotFoundError: No module named 'int'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'int' How to remove the ModuleNotFoundError: No module named 'int' error
Compare a int buffer with another int buffer.
Compare a int buffer with another int buffer.  In this tutorial, we will see how to compare a int buffer with another int buffer. IntBuffer API... static IntBuffer allocate(int capacity) 
php parse string as int
php parse string as int  While trying to pass string to int using int() i get the following error: Call to undefined function int() Why it is throwing an error
convert date time to int
convert date time to int  convert date time to int
Double To Int Without TypeCasting
Double To Int Without TypeCasting  How to convert Double to Int without using typecasting?   class ConvertDoubleToInt { public static void main(String[] args) { double d=25.5; int num=new
Write a int value into int buffer at given index.
Write a int value into int buffer at given index.  In this tutorial, we will see how to write the given int value into int buffer at the given ...(int capacity)  The allocate(..) method allocate a new int buffer
Create a int buffer by wrapping an int array into a buffer.
Create a int buffer by wrapping an int array into a buffer.  In this tutorial, we will see how to create a int buffer by wrapping an int array... type Method Description static IntBuffer wrap(int
conver object to int
conver object to int  i have a method returns object but i need int how can convert ? notice:object not means string means object string str map.get(str)ADS_TO_REPLACE_1 returns object but i need an integer
NSInteger from int
NSInteger from int  Hi, How to initialize NSInteger from int variable? Thanks   Hi, you might do it as shown below: NSInteger i = 10; Let's know if you have any better code. Thanks
Converting string to Int - JDBC
Friend, Use the following code to convert string to int. Integer i
Transfer the content of a int buffer into another int buffer.
; } } Output C:>java BufferToBuffer Int...Transfer the content of a int buffer into another int buffer.  In this tutorial, we will see how to transfer the content of a int buffer into another
String lastIndexOf(int ch, int fromIndex)
explanation about the lastindexOf(int ch, int fromIndex) method of String class. We are going to use lastindexOf(int ch, int fromIndex) method of String class in Java... String lastIndexOf(int ch, int fromIndex)   
String indexOf(int ch, int fromIndex)
about the indexOf(int ch, int fromIndex) method of String class. We are going to use indexOf(int ch, int fromIndex) method of String class in Java... String indexOf(int ch, int fromIndex)   
ModuleNotFoundError: No module named 'int-hash-int-hash-lib'
ModuleNotFoundError: No module named 'int-hash-int-hash-lib'  Hi...: No module named 'int-hash-int-hash-lib' How to remove the ModuleNotFoundError: No module named 'int-hash-int-hash-lib' error? Thanks   Hi
ModuleNotFoundError: No module named 'int-set'
ModuleNotFoundError: No module named 'int-set'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'int-set' How to remove the ModuleNotFoundError: No module named 'int-set
ModuleNotFoundError: No module named 'extended-int'
ModuleNotFoundError: No module named 'extended-int'  Hi, My Python... 'extended-int' How to remove the ModuleNotFoundError: No module named 'extended-int' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'int_date'
ModuleNotFoundError: No module named 'int_date'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'int_date' How to remove the ModuleNotFoundError: No module named 'int_date
ModuleNotFoundError: No module named 'int-py'
ModuleNotFoundError: No module named 'int-py'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'int-py' How to remove the ModuleNotFoundError: No module named 'int-py'
ModuleNotFoundError: No module named 'int-set'
ModuleNotFoundError: No module named 'int-set'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'int-set' How to remove the ModuleNotFoundError: No module named 'int-set
ModuleNotFoundError: No module named 'int-to-byte'
ModuleNotFoundError: No module named 'int-to-byte'  Hi, My Python... 'int-to-byte' How to remove the ModuleNotFoundError: No module named 'int-to-byte' error? Thanks   Hi, In your python environment
int Array
int Array       ... have declared an array of type int then the array will take only the int values...;Using int Array in jsp</TITLE> </HEAD> <BODY> <
How to transfer data from int buffer to int array.
How to transfer data from int buffer to int array.  In this tutorial, we will discuss how to transfer data from int buffer to int array. IntBuffer... Description static IntBuffer wrap(int[] array)   
Convert Object to Int
:\vinod>java ObjectToInt Numeric string to primitive int = 123... Convert Object to Int      ... Object into a primitive type int and Integer Object to primitive type int. . 
Creates a read-only int buffer that shares the content of int buffer.
Creates a read-only int buffer that shares the content of int buffer. In this tutorial, we will see how to creates a read-only int buffer that shares the content of int buffer. IntBuffer API : The java.nio.IntBuffer class extends

Ads