Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Reading your txt file
Index -> Programming, Java -> Java Submissions
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
r.m_spy




PostPosted: 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)
{
}
}
}



FileDemo.java
 Description:
the java version

Download
 Filename:  FileDemo.java
 Filesize:  1019 Bytes
 Downloaded:  267 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
r.m_spy




PostPosted: Mon Apr 26, 2010 7:31 pm   Post subject: RE:Reading your txt file

really, no one want to read
USEC_OFFICER




PostPosted: 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




PostPosted: 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




PostPosted: Wed Jan 09, 2013 12:52 pm   Post subject: Re: Reading your txt file

i dont get this program. it doesnt work
Insectoid




PostPosted: 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?
Display posts from previous:   
   Index -> Programming, Java -> Java Submissions
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 6 Posts ]
Jump to:   


Style:  
Search: