hello i have just started to learn java by myself and i am stuck here with this example i want to show a file in console please tell me where am i making mistake.
i am getting erroe variable fin maight not be initialised
here is the code
CODE
/** Display a text file To use this program,specify the name of file that you want to see */ import java.io.*; class showfile { public static void main(String args[])throws IOException { int i; FileInputStream fin; try { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); System.out.print("Enter file name:"); String filename=br.readLine(); fin=new FileInputStream(filename);
} catch(FileNotFoundException e) { System.out.println("File not found"); return;
You are getting that error because it is telling you that fin may not be set since your doing that in the try&catch loop, and then you are doing methods of the FileInputStream class with a variable that possibly may be empty. Put your do-while loop and fin.close(); inside the try, or you could try setting fin to an empty file if you want in the two catches, but I'm not sure if that would work or not. Your best bet is to move the do-while loop and your fin.close();
} catch(FileNotFoundException e) { System.out.println("File not found"); return;
}
You have a couple problems yet. First, you should not declare the file input stream in the same try/catch as the BufferedReader on standard input. Separate these. Also, you are continuously redefining the InputStream in the later part of the code, which will make the program simply run an infinite loop. A corrected version of the code would look something like this (depending upon what you wanted it exactly to do):
CODE
/** Display a text file To use this program,specify the name of file that you want to see */ import java.io.*; class showfile { public static void main(String args[])throws IOException { int i; FileInputStream fin; String filename = ""; try { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); System.out.print("Enter file name:"); filename=br.readLine();
} catch(FileNotFoundException e) { System.out.println("File not found"); return;
} catch(ArrayIndexOutOfBoundsException e) { System.out.println("Ussag:Showfile file"); } //Open the FileInputStream try{ fin=new FileInputStream(filename); } catch(FileNotFoundException e){ e.printStackTrace(); System.out.println("File not found"); return; } //Read characters untill Eof id encountered do { i=fin.read(); if(i!=-1) System.out.println((char)i); } while(i!=-1); fin.close(); } }
If you have any questions, just let me know. I hope this helps!
Even though its not good programing practice, defining BufferedReader in the try was not causing any error because it was not being referenced at all outside of the block. And as for the infinite loop, that wont happen unless the file is infinitely long which is impossible.
hi... I'm new here... /smile.gif" style="vertical-align:middle" emoid=":)" border="0"
alt="smile.gif" /> OK, can you help me... to find a money making website??? I'm in 'out of
money' now... /sad.gif" style="vertical-align:middle" emoid=":(" border="0" alt="sad.gif" />
Thanks for helping.......
Well this is a program that i joined 3 days ago. Some ppl say that they make from 50$ to
100$ with it but i don't know how you could. I make about 3$/day with this, so about
90$/month can pay for your domain and some paid hosting if u are into this stuff, or some beers
at the pub /smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" /> What
do you have to do: convince ppl to install they're toolbar. The problem is that the tool bar is
picked up by anti virus software like a trojen so.. i'ts hard to get installs. ....
Okay me and some friends are making a movie. It's about a Jewish boy and a German Aryan girl
who fall in love during the holocaust. We need some ideas for a plot and set pieces, ect ect. And
jusst any general suggestions. Any help would be GREATLY appreciated. Thanks. <33....
----------------------- Game Making ::Simple Attack Script:: Ok, When making my first, ok well
second ..ok , my current and third one (first 2 were really bad, but then i found out my own way on
how to make an idea script), I would always first write down or think of the stats of the character.
For the purpose of this tut, i will be using space-ship kinda stats(since my first proper attack
script was a space battle script) : The Attack Stats : -Accuracy(Aim) -Hull Damage(Main Dmg.)
Defense Stats : -Shield Power(Armor) -Speed(dodge/swiftness) ATTACK/DAMAGE ....
Hi, do you know what is the mistake in the following PHP code: It does give me the following
message: QUOTE Parse error: syntax error, unexpected $end in
/home/alex1985/public_html/mulhim/library_project/test_dir/newjoke.php on line 68 CODE
<?php $dbcnx = @mysql_connect('localhost', 'root',
'mypasswd'); if (!$dbcnx) { exit('<p>Unable to connect
to the ' . 'database server at this time.</p>'); } if
(!@mysql_select_db('ijdb')) { e....
Hi, everyone! What is the mistake over here? CREATE TABLE '1_users' ( 'id'
INT(11) NOT NULL AUTO_INCREMENT, 'username' VARCHAR(255) NOT NULL, 'password'
VARCHAR(255) NOT NULL, PRIMARY KEY ('id') ) TYPE MYISAM; The PHPMyAdmin states: QUOTE
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server
version for the right syntax to use near ''1_users' ( 'id' INT(11) NOT NULL
AUTO_INCREMENT, 'username' VARCHAR(255) NOT ' at line 1 Please, let me k....
Recently, I had a need to make a FTP client, since our webhosting FTP server was kind of exotic, and
very restrictive, and most of uploads, even though they reach 100% would crash... File would be
uploaded to a server, but FTP clients just froze upon completion, waiting for the 226 (OK) from FTP
server... So, I had to make my own, one who would not wait for 226, but instead, watch the file
pload progress... This tutorial is not fuly complete, in the sense that it does not offer COMPLETE
FTP client functionality (for example, I ddn't write the code for FTP download, ....
I've heard of various websites that make money through the actual websites. However, how would
you make that money? Would you sell things? Services? I need a few ideas. Moved from Business to
Making Money Online. Please take the time to learn the Forum Structure better and post Topics
accordingly. Thanks. ....
Hey, if you came here to find out how to make money online, then here you are. This site was one I
made in freewebs so I can get referrals and you guys can make money. The site is...
www.freewebs.com/hyangkim60 Go on the site and you guys can see how my friends made money. They
advised it so I tried and now I am sharing with you too. Good luck!....
Recently, I've lost a lot of money to an identity theft issue and so I went in search of ways to
make money. I looked all sorts of sites and while I found a few that paid well, none stuck out at me
more than Cash Crate. Cash Crate is an amazing website that pays for each referral you get, as well
as gives you a high percentage of everything your referrals make. Anyways, I signed up, and after
getting a lot of referrals, my income this month has doubled and I haven't done any surveys at
all in a few weeks. So go there, and do some surveys..get some referrals. I....
Like everyone in here does, I design websites. There was this man whom I met and who wanted a
website designed for his Non Governmental Organization and another website designed for a Tourism
company he wanna start off with some other people. After looking at the mightiness of the job, I
told him that he would be paying the sum of N550,000 ($4,230 approx). He said that he doesnt
have that kinda money at the moment, but he also made me a proposal which is: Design the website
and get paid.... or Design the website and dont get paid but you will get a share in the tou....
So has any one here ever done it the easy ways (Make Money). What I mean by this is the surveys
sites and other Get Rich Online methods. I used to try doing online surveys for a bit of money,
however I never earned any, as most of them required me to subscribe for affiliate offers. So
because of the success I never had myself, I was wondering if any of you have actually made any
either?....
Seriously, the number of topcs exactly the same over xbox 360 or ps3 or wii is stupid. No-one is
getting anything out of such topics here at the trap, and everytime a new person seems to register,
a new topic seems to show up. These are always "I can't decide on xbox of ps3 help?" Blah!
Now come on, PLEASE stop making these topics. Do your own research, instead of for the sake of
posting and simply get whichever one you want. After all it's your choice in the end!!
Post a nice detailed review if you really want to help people out and help yourself wi....
According to RuneScape TOS, as long as your private server does not connect/interfere with the
actual server this 3rd party software is not breaking the real RuneScape TOS. Please use this
information accordingly. If any RuneScape representative feels that this post is against your TOS,
please contact Trap17 admins via PM or email. Thank you. This is part 1, focused on making a
private server and such, if you would like, i will post more on customization in other parts.
Overview: This guide will explain the basics for building your very own rs private server&....
Hi. /smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" /> I just
wanted everyone to know(if you didn't know already. /smile.gif" style="vertical-align:middle"
emoid=":)" border="0" alt="smile.gif" />) of a pretty cool program called Game Maker. From my
experience with it, it's very simple, yet you can still make awesome games with it. Now, when I
say "awesome" keep in mind, you won't be able to make games like "Halo" or something like that
with it. But you can make pretty cool games still, it is capable of 2D and 3D games, alth....
I would just like to hear from anyone who has used google adsense if they have made any good money
while using G.A. And if you did have luck what sort of website content do you have on your website
?? i'm interested to sart a site and sign up for google adsense but i not tooo sure what type of
site to build so i just wanted to get a better idea before i go to work on this !
/cool.gif" style="vertical-align:middle" emoid="B)" border="0" alt="cool.gif" /> Hello I am
posting this site here as I am making money with it every month..It is a step-by-step money making
system..Best thing is it is 100% free..First I thought that it might be a scam but now as I am
making 4000$ per moth so now I have to believe it.. I will advise you that
please give it a try before making any decision..You will also make money..no experience is needed
and its free..so you have nothing to lose.. you will surely love it.. ....
Im back again with what i think it would be an interesting tutorial for all of you guys who wants to
take flash out of the web and make really cool interactive CDS. First of all if all of you are
thinking right now: "this dude is wrong for making interactive cds you have to use macromedia
Director", well you are right macromedia director it's used to build interactive cds and dvds
among other things, but you can also make interactive cds with Flash, the thing is: if you want to
make a simple interactive CD you can totally do it with flash, of course Director brings ....
Hello Guys, I have made a New Site Enjoy it, hope it helps. My Site /laugh.gif'
border='0' style='vertical-align:middle' alt='laugh.gif' /> Its Not Totaly Fnished ... merged
posts. ....
does anybody know how to make a scrollbar for my game page I am making on my site. This whole site
is completely in flash. I know how to make a scrollbar for just words but not when there is an
image on there also. Does anybody know?....
Ok a have a question.. I searched google but i didn't find a lot of stuff. So here is my
problem: I have DSL connection on my cousin's computer and i want the computer to auto connect
on windows startup...I have copied the shortcut of my connection to startup folder but it doesent
want to connect /tongue.gif' border='0' style='vertical-align:middle' alt='tongue.gif' /> anyone
knows some other tricks for this? /smile.gif' border='0' style='vertical-align:middle'
alt='smile.gif' /> ....
hey im making a gunz online clan you have to be over lvl 10 to get in fill in this form gunz
name: country: plays a week: time(in GBA) play: level:....
**** This tutorial will show you how to put files into .rar Archive and pass worded (if wanted)
**** What You Will Need Before continuing you will need a couple of thing, first of all you
need WINRAR , which is a very powerful archive manager. It can reduce size for you email
attachments, decompress RAR, ZIP and other types of files downloaded from the internet. You can get
winrar at http://www.rarlabs.com The other thing is that make sure your using Windows XP because
this is what I used to make this tutorial. I think it works with any other windows not....
Website Ideas I'm deciding to take down my site, it's getting kind of old and
boring, but I don't want to just stop with having a site. I need some ideas for something that
provides a service of some sort to people. There are millions of blogs, I really don't want to
post about my life on a daily basis anyway. All ideas will be welcomed, I can't seem to think
of anything at all, so Im asking you. What could my new website be about?....
Inbox Dollars is a great site that i found when i was browsing around the net. This Site Offers you
3 different reward chioces and they are: - 10000 Banner Imprressions- $10 - Gold Membership
-$17 - Check- $30 I have already gotten the 10000 banner impressoins from them. The ways
you can earn money are: -$5 when you join the site... -$0.01-0.10 for every paid email
-$4 for every survey site you join -Up to $50 for for every offer -Unlimited cash for
games -Umlimited cash for shoppings The offers are very easy to fill out and you ge....
Hey all, Over the last few years I have been experimenting with making money over the internet.
Being a very creative person I naturally took on to web design. However, I soon found that it was
too time consuming for my liking and it rarely paidf off. Whilst playing around with Photoshop
which someone bough me as a present I started to learn the essential techniques of graphic
designers. Before I knew it I was able to make basic logos that could be sold at a price. Not long
after discovering this I found a site that did forum auctions on logos. A customer requests a ....
Hiiiiii Any one playing The Sims 2 must have heard from Bodyshop, or is even very handy with it
and makes his own clothes to use in the game...!! Well Those people I'd like to ask
about some tip or tricks, because, I tried making clothes, and were pretty on the good way so far,
but I just kinda have the feeling I dont know all the tricks yet!! Anybody who is familiar
with this program can leave some tips/tricks, also for others who want to create great clothes for
their sims???? Thanksss so very much, I have this outfit in my head, but have no ide....
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE
forum, Create your own topics, Ask Questions, track topics, setup
subscriptions & notifications and Get a Free Website w/ Email and FTP.