Reading your txt file
Author |
Message |
r.m_spy
|
Posted: Fri Apr 23, 2010 5:13 pm Post subject: Reading your txt file |
|
|
import java.io.*;
class FileRead
{
public static void main(String [] args)
{
int cent;
System.out.println("Please enter the line you want to read(put 0 if you want to read the full text)");
cent=In.getInt();
System.out.println("");
System.out.println("");
System.out.println("");
if (cent==0)
{
readmyfile("C://greet.txt");
}
else
readmysentence("C://greet.txt",cent);
}
public static void readmyfile(String file)
{
try
{
FileReader fr=new FileReader(file);
BufferedReader br=new BufferedReader(fr);
String line;
for(int count=2;(line = br.readLine())!=null;count++)
{
System.out.println(count-1+". "+line);
}
br.close();
}
catch(IOException e)
{
}
}
public static void readmysentence(String file,int num)
{
try
{
FileReader fr=new FileReader(file);
BufferedReader br=new BufferedReader(fr);
String line;
for(int count=0;(line = br.readLine())!=null;count++)
{
if (num-1==count)
{
System.out.println(num+". "+line);
}
}
br.close();
}
catch(IOException e)
{
}
}
}
Description: |
|
Download |
Filename: |
FileDemo.java |
Filesize: |
1019 Bytes |
Downloaded: |
398 Time(s) |
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
r.m_spy
|
Posted: Mon Apr 26, 2010 7:31 pm Post subject: RE:Reading your txt file |
|
|
really, no one want to read
|
|
|
|
|
|
USEC_OFFICER
|
Posted: Mon Apr 26, 2010 8:12 pm Post subject: RE:Reading your txt file |
|
|
We already talked about this. You should have put all these simple Java files in one topic. This program might be more useful in the Java walkthrough page, list, thingy if you explained what you did.
Also, are you working on something new now? You should be after displaying a solid grounding in Java programming. (I'm supposted to be doing English homework, In case my language seems flowery.)
|
|
|
|
|
|
Unnamed.t
|
Posted: Wed May 26, 2010 6:17 pm Post subject: Re: Reading your txt file |
|
|
The way you have manipulated the IO stream to get input is rather impressive than just using a traditional bufferedreader (filereader ("filename"))
As said before, I think it would serve a better job in the compsci community by putting the code in the walkthrough page.
Also I wanted to mention some difficulty I had while reading your code. I highly recommend you to use syntax highlighting when displaying code. This could be done by adding the following tags :
[syntax="language (in this case, java)"]
[/syntax]
You can learn more useful things about tags and display for this forum at
http://compsci.ca/v3/posting.php?mode=reply&t=24925
|
|
|
|
|
|
Programmer1996
|
Posted: Wed Jan 09, 2013 12:52 pm Post subject: Re: Reading your txt file |
|
|
i dont get this program. it doesnt work
|
|
|
|
|
|
Insectoid
|
Posted: Wed Jan 09, 2013 6:08 pm Post subject: RE:Reading your txt file |
|
|
code: | readmyfile("C://greet.txt"); |
Does this file exist on your computer?
|
|
|
|
|
|
|
|