Computer Science Canada

Reading your txt file

Author:  r.m_spy [ 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)
{
}
}
}

Author:  r.m_spy [ Mon Apr 26, 2010 7:31 pm ]
Post subject:  RE:Reading your txt file

really, no one want to read

Author:  USEC_OFFICER [ 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.)

Author:  Unnamed.t [ 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

Author:  Programmer1996 [ Wed Jan 09, 2013 12:52 pm ]
Post subject:  Re: Reading your txt file

i dont get this program. it doesnt work

Author:  Insectoid [ 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?


: