java.lang.Object
java.io.Reader
java.io.BufferedReader
java.io.LineNumberReader
- All Implemented Interfaces:
- Closeable, Readable
- See Also:
- Top Examples, Source Code
public int getLineNumber()
- See Also:
setLineNumber(int)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public LineNumberReader(Reader in)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public LineNumberReader(Reader in,
int sz)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public void mark(int readAheadLimit)
throws IOException
- See Also:
- BufferedReader
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public int read()
throws IOException
- See Also:
- BufferedReader
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public int read(char[] cbuf,
int off,
int len)
throws IOException
- See Also:
- BufferedReader
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
[551]Random file read write
By Anonymous on 2004/04/22 06:36:30 Rate
import java.io.*;
import java.lang.*;
public class MyReader {
public static void main ( String [ ] args ) {
try
{
BufferedReader filein = new BufferedReader ( new FileReader ( "C:\\Otaria.txt" ) ) ;
int numLines = 0;
int random = 0;
String currentLine = null;
String provvi = null;
String giocatore=null;
String gioca=null;
boolean ok = false;
while ( ( currentLine=filein.readLine ( ) ) != null )
{
numLines++;
}
filein.close ( ) ;
random = ( int ) ( Math.random ( ) *numLines ) ;
do
{
filein = new BufferedReader ( new FileReader ( "C:\\Otaria.txt" ) ) ;
for ( int i=0;i < random;i++ )
{
filein.readLine ( ) ;
}
giocatore=filein.readLine ( ) .trim ( ) ;
filein.close ( ) ;
if ( ( !giocatore.equals ( "PORTIERI" ) ) &&
( !giocatore.equals ( "DIFENSORI" ) ) &&
( !giocatore.equals ( "CENTROCAMPISTI" ) ) &&
( !giocatore.equals ( "ATTACCANTI" ) ) &&
( !giocatore.equals ( "" ) ) )
ok = true;
}
while ( !ok && ( giocatore != null ) ) ;
System.out.println ( giocatore ) ;
filein = new BufferedReader ( new FileReader ( "C:\\Otaria.txt" ) ) ;
BufferedWriter fileou = new BufferedWriter ( new FileWriter ( "C:\\Foca.txt" ) ) ;
for ( int r=0;r < numLines;r++ )
{
if ( r != random )
fileou.write ( filein.readLine ( ) +"\r\n" ) ;
else
filein.readLine ( ) ;
}
filein.close ( ) ;
fileou.close ( ) ;
}
catch ( IOException e )
{
e.printStackTrace ( ) ;
System.out.println ( "ERRORE" ) ;
}
}
}
public String readLine()
throws IOException
- See Also:
- BufferedReader
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
[1212]How many lines available in the particular file.Plz send me code for this??
By ashpak_pathan { at } rediffmail { dot } com on 2004/12/21 09:12:20 Rate
I want to the line number of the file that how many lines available in the particular file.Plz send me code for this.
public static void main ( String [ ] args ) {
try
{
//BufferedReader filein = new BufferedReader ( new FileReader ( "D:\\Yahoo.csv" ) ) ;
FileReader fr = new FileReader ( "D:\\ash.txt" ) ;
LineNumberReader lr = new LineNumberReader ( fr ) ;
String s = lr.readLine ( ) ;
int Num=0;
if ( s != null ) {
Num=lr.getLineNumber ( ) ;
System.out.println ( "The Line No is "+ Num ) ;
}
Num++;
lr.close ( ) ;
}
catch ( IOException e )
{
e.printStackTrace ( ) ;
System.out.println ( "ERRORE" ) ;
}
}
}
public void reset()
throws IOException
- See Also:
- BufferedReader
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public void setLineNumber(int lineNumber)
- See Also:
getLineNumber()
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public long skip(long n)
throws IOException
- See Also:
- IllegalArgumentException, BufferedReader
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples