a program that send to several files

Hi all

how can i create a program that send data to diff files according to some Criteria

i.e. i have the following line

male(john 23 teacher) femal( mary 18 student) thing (flower pink)

thing (book blue) male(john 23 teacher) femal( mary 18 student)

how can i send the male information to male file and femal information to femal file and thing inforamtion to thing files?

any idea?

[427 byte] By [TheNewLeadera] at [2007-11-27 8:17:26]
# 1
Yes: if / else would be a good start.
quittea at 2007-7-12 20:02:36 > top of Java-index,Java Essentials,Java Programming...
# 2
how can i use if and else
TheNewLeadera at 2007-7-12 20:02:36 > top of Java-index,Java Essentials,Java Programming...
# 3
> how can i use if and else152 posts and you can't do that yet? Read a tutorial
georgemca at 2007-7-12 20:02:36 > top of Java-index,Java Essentials,Java Programming...
# 4

if(male){

OPEN FILE

WRITE/APPEND MALE INFO

CLOSE FILE

}else if(female){

OPEN FILE

WRITE/APPEND FEMALE INFO

CLOSE FILE

}else{

throw new GayUnsupportedOperationException()

}

mleiria

manuel.leiriaa at 2007-7-12 20:02:36 > top of Java-index,Java Essentials,Java Programming...
# 5
> throw new GayUnsupportedOperationException()Those Exceptions seem to be prevalent in all my code. Duz any1 no y? ugrent
Djaunla at 2007-7-12 20:02:36 > top of Java-index,Java Essentials,Java Programming...
# 6
you'll just have to catch it with something.:)best regards,Manuel Leiria
manuel.leiriaa at 2007-7-12 20:02:36 > top of Java-index,Java Essentials,Java Programming...
# 7
it is not that i don't know how to use the if/else but i thought that in one session we are just allowed to open one file not many as suggested
TheNewLeadera at 2007-7-12 20:02:36 > top of Java-index,Java Essentials,Java Programming...
# 8
> it is not that i don't know how to use the if/else> but i thought that in one session we are just allowed> to open one file not many as suggestedWhere did you get that idea, and what do you mean by "one session"?
jverda at 2007-7-12 20:02:36 > top of Java-index,Java Essentials,Java Programming...
# 9
one session?I believe that three rounds of douch?is commonly regarded as "a session".Then it's time to change ends, and everyone has a light snack, and you go back the other way.Then everyone greens out, and it's time to mow the lawn again, apparently.;-)
corlettka at 2007-7-12 20:02:36 > top of Java-index,Java Essentials,Java Programming...
# 10

by a session i mean one run at a time

i thought that i just can open one file at each run for a program

regarding the suggested code of if/else

if(male){

OPEN FILE

WRITE/APPEND MALE INFO

CLOSE FILE

}else if(female){

OPEN FILE

WRITE/APPEND FEMALE INFO

CLOSE FILE

}else{

throw new GayUnsupportedOperationException()

}

how does the code if it is male will take everything before the next type

becuase here i have several types in one line by type i mean male, female or thing

and each one can be repeated as the give example

so if i have a loop to read the whole file line by line then the above if/else

how can it word?

TheNewLeadera at 2007-7-12 20:02:36 > top of Java-index,Java Essentials,Java Programming...
# 11
That was funny new GayExceptionHauhuA
charllescubaa at 2007-7-12 20:02:36 > top of Java-index,Java Essentials,Java Programming...
# 12
> by a session i mean one run at a time> i thought that i just can open one file at each run> for a programWhere did you get that idea? That would be a pointless and crippling restriction.
jverda at 2007-7-12 20:02:36 > top of Java-index,Java Essentials,Java Programming...
# 13

Imagine if you will that this is rather well to do Rastifarian session, and several receptacles are circulating concurrently. ;-)

open hisFile or die

open herFile or die

open GWsFile or die

opne inputFile or die

foreach line in inputFile do

foreach record in line

select case of (recordType)

case male: write to hisFile

case female: write to hisFile

case genderAmbigious: write to GWsFile

end select

next record

next line

close all files

corlettka at 2007-7-12 20:02:36 > top of Java-index,Java Essentials,Java Programming...
# 14
may i ask what is foreach record in lineare you contacting a database?and do you mean to close the file by "die"?
TheNewLeadera at 2007-7-12 20:02:36 > top of Java-index,Java Essentials,Java Programming...
# 15
foreach... for each record on the linedie... http://www.youtube.com/watch?v=NM22G7vrlaA
corlettka at 2007-7-21 22:35:23 > top of Java-index,Java Essentials,Java Programming...
# 16

by a session i mean one run at a time

i thought that i just can open one file at each run for a program

regarding the suggested code of if/else

if(male){

OPEN FILE

WRITE/APPEND MALE INFO

CLOSE FILE

}else if(female){

OPEN FILE

WRITE/APPEND FEMALE INFO

CLOSE FILE

}else{

throw new GayUnsupportedOperationException()

}

how does the code if it is male will take everything before the next type

becuase here i have several types in one line by type i mean male, female or thing

and each one can be repeated as the give example

so if i have a loop to read the whole file line by line then the above if/else

how can it word?

TheNewLeadera at 2007-7-21 22:35:23 > top of Java-index,Java Essentials,Java Programming...
# 17
corlettkit is not funnyeither you answer the question or keep others who knows to answer it
TheNewLeadera at 2007-7-21 22:35:23 > top of Java-index,Java Essentials,Java Programming...
# 18

> corlettk

> it is not funny

>

> either you answer the question or keep others who

> knows to answer it

That's a way to piss off a whole lot of people and make nobody want to help you.

These are public forums, and the questions are answered by volunteers. Part of the appeal of posting here is the humor and the random, pointless discussions. If you can't handle that, pay somebody big bucks to be your personal private Java tutor and yes-man.

jverda at 2007-7-21 22:35:23 > top of Java-index,Java Essentials,Java Programming...
# 19

by a session i mean one run at a time

i thought that i just can open one file at each run for a program

regarding the suggested code of if/else

if(male){

OPEN FILE

WRITE/APPEND MALE INFO

CLOSE FILE

}else if(female){

OPEN FILE

WRITE/APPEND FEMALE INFO

CLOSE FILE

}else{

throw new GayUnsupportedOperationException()

}

how does the code if it is male will take everything before the next type

becuase here i have several types in one line by type i mean male, female or thing

and each one can be repeated as the give example

so if i have a loop to read the whole file line by line then the above if/else

how can it word?

TheNewLeadera at 2007-7-21 22:35:23 > top of Java-index,Java Essentials,Java Programming...
# 20
1- read the line 2- open 3 files3- send data to each one where is the problem ?
eaajea at 2007-7-21 22:35:23 > top of Java-index,Java Essentials,Java Programming...
# 21

> by a session i mean one run at a time

> i thought that i just can open one file at each run

> for a program

You've already been told that's not the case. I don't know where you'd get such silly idea to start with. Why don't you start writing some code?

> how does the code if it is male will take everything

> before the next type

> becuase here i have several types in one line by type

> i mean male, female or thing

> and each one can be repeated as the give example

> so if i have a loop to read the whole file line by

> line then the above if/else

> how can it word?

I have no idea what you mean here.

jverda at 2007-7-21 22:35:23 > top of Java-index,Java Essentials,Java Programming...
# 22
send data to each one can this be done by if/else?regarding the open file can i write the same file to two different locationfor example in c and d drives?
TheNewLeadera at 2007-7-21 22:35:23 > top of Java-index,Java Essentials,Java Programming...
# 23

> send data to each one

>

> can this be done by if/else?

yes

>

> regarding the open file can i write the same file to

> two different location

> for example in c and d drives?

I don't see why you couldn't have that functionality?

petes1234a at 2007-7-21 22:35:23 > top of Java-index,Java Essentials,Java Programming...
# 24

> ...

> regarding the open file can i write the same file to

> two different location

> for example in c and d drives?

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

Post back if you have a specific question about (your) code.

prometheuzza at 2007-7-21 22:35:23 > top of Java-index,Java Essentials,Java Programming...
# 25
> send data to each one > > can this be done by if/else?> > regarding the open file can i write the same file to> two different location> for example in c and d drives?JEEZUS! Try it out already!
jverda at 2007-7-21 22:35:23 > top of Java-index,Java Essentials,Java Programming...
# 26

still i don't know how to do it

i think of tokinzing the line, but how can i do the fo;;owing

if it is man type take everything between brackets

and save it

what to write inside the if statment

so if it is male

the output will be save in male is

john 23 teacher

jo24 singerr

male(john 23 teacher) femal( mary 18 student) thing (flower pink)

thing (book blue) male(jo24 singerr) femal( mary 18 student)

StringTokinzer st = new StringTokinzer(line)

if (type=man)

{

}

if (type=woman)

{

}

if (type=thing)

{

}

TheNewLeadera at 2007-7-21 22:35:23 > top of Java-index,Java Essentials,Java Programming...
# 27
I have no idea what you're asking or what you're trying to do.
jverda at 2007-7-21 22:35:23 > top of Java-index,Java Essentials,Java Programming...
# 28
Well, what do you want to do if it's a man? Put the code for that in the appropriate if block.
jverda at 2007-7-21 22:35:23 > top of Java-index,Java Essentials,Java Programming...
# 29
if i know the code i will not askif it is man then what code should i write to have as out putjohn 23 teacherjo 24 singerrwhich coem between the () after the type man
TheNewLeadera at 2007-7-21 22:35:23 > top of Java-index,Java Essentials,Java Programming...
# 30
so this program will send to 3 the files:man womanthingwhat come after each type between ()as said before
TheNewLeadera at 2007-7-21 22:35:28 > top of Java-index,Java Essentials,Java Programming...
# 31

> so this program will send to 3 the files:

> man

> woman

> thing

>

> what come after each type between ()

>

> as said before

Do yourself a favor and find a new hobby: after more than a year you are still not able to produce something that looks like a line of Java code. Perhaps it sounds a bit harsh, but I feel it is the bitter truth.

prometheuzza at 2007-7-21 22:35:28 > top of Java-index,Java Essentials,Java Programming...
# 32
Dear prometheuzzi am asking for the idea how can i represent thatif i get the idea then i will try to have some codei know how to tokinze the sentece, and how to write to file alos how use if elsebut i don't know how to handle the info inside the brackets
TheNewLeadera at 2007-7-21 22:35:28 > top of Java-index,Java Essentials,Java Programming...
# 33

> Dear prometheuzz

>

> i am asking for the idea how can i represent that

> if i get the idea then i will try to have some code

>

> i know how to tokinze the sentece, and how to write

> to file alos how use if else

> but i don't know how to handle the info inside the

> brackets

Post what you have so far and explain where you're stuck at the moment. And use code tags please.

prometheuzza at 2007-7-21 22:35:28 > top of Java-index,Java Essentials,Java Programming...
# 34

> i know how to tokinze the sentece, and how to write

> to file alos how use if else

> but i don't know how to handle the info inside the

> brackets

What else is there to put there besides what you said you already know?

You're not communicating your problem well at all, and you seem scared to actually *TRY* something.

Try it, for ****'s sake! Write *REAL* Java code inside a real class that you can compile. Do as much as you can, and when you get stuck, ask a specific question and use the real code you've written to help clarify it.

If you can't do that, there's no hope.

jverda at 2007-7-21 22:35:28 > top of Java-index,Java Essentials,Java Programming...