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, Im working on a website, and im trying to make a right-click menu, which opens on right click,
wherever the cursor is, and closes on mouse out. I wrote the code below, and when i ran it in IE it
ran fine, just how i wanted it to work. However in firefox, the menu just opened in the top left. im
presuming this is because it doesnt like my style changing in the javascript. Any ideas, and
suggestions? If i cant make this work, i will just make it so it works slightly differently when
viewev in firefox so that it can just open in one place. All ideas appreciated. ....
Well First off this is just a simple Tutorial on how to make a Realistic Clouds Background First
off you'll need Adobe Photo Shop, After getting that you'll need a Brain, a pair of hands,
and a few Basic Photo Shop Skills! I Created this when I first Started using Photo Shop So this
shouldn't be an issue. okay First step : Open a new RGB Background with Transparency. CODE
File -> New Make the Settings look like this Name : Clouds Preset : Custom Size :
Width : 500 | Pixels Height : 500 | Pixels Resolution : 72.009 | Pixels/Inch Color ....
I think this should be easy for someone experienced, but I have never done something similar, so I
need a bit of guidance. I have a mini-site under a subdomain that entirelly relies on dynamic URIs.
All pages have URIs in the form http://towo.dragon-tech.org/index.php?lang...mp;section=news
http://towo.dragon-tech.org/index.php?lang...mp;section=home and so on. The index.php script takes
care of retrieving the appropriate content from both the database and some include files, and
everything is working fine. Only that these URIs look quite ugly on any visitor's....
i have a question, would somebody tell me the software (if there any) of making video when we use
some applications in our computer, it's like a tutorial video, if you answer it using the video
camera it was a bad job, but i think it uses a software/an application which records our activity
when we use our computer.. hmmm.. sorry guys if i seem so idiot, but i need an answer... thanks
before.....
this is one thing i've struggled with for ages. I want a webpage where there are little
thumbnails and in the middle somewhere is the main picture. The littole thumbnails or snipets of
infor when clicked display the main image corresponding to that clicked thumbnail or link. e.g
pictures of the country side listed in pairs or 3's or 4's in a column and you click each
one an the main view on the screen displays that particular picture. How is this achieved. Can any
one gimme a link to a site with templated for that or javascript for that or html code or past....
I propose the idea that giving free premium software to those who could never afford a purchase can
only help the owners of that software. Some say that if a sale was never going to happen it
can't be a lost sale. I agree. If people can get started learning to use programs they could
never buy, they may develop skills and abilities that would enable future revenue and loyalty. At
the same, time a third world nation can have more development as skilled and trained professionals
grow. Another important issue would be addressed as well. Piracy. By lifting the copyrig....
Specs Hardness: 1 Time: about 2 minutes Needings: -A (small) brain -A keyboard -MS Paint
Steps: 1. Press the Print Screen button on your keyboard. 2. Open Microsoft Paint. 3. Paste
(CTRL+V). 4. Save/Edit the image. (I prefer saving as .png or .tif) ét voila, you've just got
yourself a picture /wink.gif" style="vertical-align:middle" emoid=";)" border="0" alt="wink.gif"
/>....
Specs Hardness: 4 / 10 Time: about 10 minutes Result: My .PSD File: Download it now!
Needings: -Basic Photoshop knowlegend. -Adobe Photoshop CS2 (Or CS3/CS4) -Brushes set ( available
here ) -A render ( available here ) Basic knowlegend: Steps: 01. Open Adobe Photoshop,
and go File > New. 02. select the sizes Width: 350 pixels . Height: 150 pixels . Press OK .
03. Press the button to maximize the window of your new project. 04. Fill your background with
black (by using the "fill" function). 05. Press F5, click on the small arrow a....
I am currently developing my own Web Browser and I need a name for it /biggrin.gif"
style="vertical-align:middle" emoid=":D" border="0" alt="biggrin.gif" /> So if you got any good
ideas please do post them /biggrin.gif" style="vertical-align:middle" emoid=":D" border="0"
alt="biggrin.gif" />....
I just want to let everyone know I have updated my list of money making websites and in my opinion
the 10 listed are the most reliable and honest money making sites that are free to join available.
Please review this blog and let me know what you think http://makeeasymoney247.blogspot.com ....
I am currently in the process of constructing a list of the best sites through which to make money
online and would like people to take a look at the sites I have added so far. I am obviously still a
long way of completing it but just wondering whether people think it is a good site / idea
http://makeeasymoney247.blogspot.com Also if you have not yet signed up to ClixSense I would
highly recommend it. You can join for free but you are better of paying the small $10 yearly
membership fee as this will bring you a ton more paid adverts - more than any other site I ....
Hi Guys This site provides a very best business opportunity making money from online and also
it is a home based business.You can earn money in profit-manner.It also provides Reverse funnel
system making money on auto pilot. Reverse funnel marketing,perpetual leverage payplan,global
resorts network,gold crown resorts,reverse funnel system,ultimate home business,fullyautomated,think
and grow rich,home biz,passive income,no phone calling,ultimate solution to home and so on. Cheer"s
Reverse funnel system making money on auto pilot ....
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, ....
ok part three now which covers the precusions setup of the small song i built for this tutorial.
the nesecery files can be downloaded here the image below is included in the precusions folder as
it mught not be entierly visable within this post so shold you need it its there also the images
purpose is to enable you to see what i am refering to within this tutorial lateron. now what i
have done above is blackd out every pattern that has nothing to do with the precusion. so the
patterns displayed in light grey are the only patterns i will be refering to. ok lets b....
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....
Found this, this morning and had to chuckle. The site has images of Select being spelt wrong on the
PS3 controller. This on the back of reading the other day, the components don't even fit into
the casing properly Oh, I do love Monday morning humour: Sony Spelling Mistake ....
maybe im to young or omsehinthing, but everyone else in my school hangs around with their friends.
Im always the one left out:( like when my p.e. teacher tells us to partner up, i can't get any
partners and im always the one that has to join a group of 3's and have to take turns or osme
crap like that. Im the one the no one likes, some of the kids at my school have a girlfriend but I
can't even get ANY friends!This is really making me angry because I want a friend and I hate
the fact that no one likes me and wants to kill me. I even have some kids that ar....
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....
can you give your ideas for my new game. if you want to help me even more then send me a private
message Thanks Tyjotr __________________________________________________ HybridHero - the new 3d
MMORPG (coming soon)....
Express your Opinions, Thoughts or Contribute your information that might help someone here.
Ask your Doubts & Queries to get answers.. "Together, We enlight each other!"
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.