• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to use print writer 2 times

 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys
need some help here with writing in a file using print writer
So the first part of my programs works ok. what I got to do next is take the numclient and the metrage values
and do another calculation with them and save in another file afterwards.
whatever I put after the close statement it writes everything in red line
I tried wiping the sortie close line and it still writes everything I put in red
Basically what I did was repeat the first line with scanner clavier and the print writer line to be able to save a new file but no dice it seems
How do you do it?
thanks
 
Saloon Keeper
Posts: 10705
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don't know what you mean by 'red'. Does your editor show it in a red color? Which editor? UTF-8 knows nothing of color.

 
Vin Ash
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
NO red means it underlines it in red..like it is a mistake
 
Carey Brown
Saloon Keeper
Posts: 10705
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I ran your code and it produced the DAT file. I opened it with the Eclipse editor and VIM editor, neither one had a problem. As a total guess, I'd say your system sees a file ending in ".DAT" and launches some application to view it and assumes the file does not contain text. Try a file name suffix of ".TXT".
 
Vin Ash
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually I think I need to do my program another way but I still hit a snag
In this version I have a file already with data about clients and an order
now the first part of my program reads it ok and puts on screen everything I have on that saved file
which is 2 strings of data
example (1234 10 . 2nd line is 2345 20)

Now the problem presents it self when I got to take each of these lines and do a mathematical process and then write it in another file
It only sees the second line but the first line it does not and thus it saves only line 2
how to make it do the maths process with all lines of that file and then save it in a new file
here is my code so far
 
Carey Brown
Saloon Keeper
Posts: 10705
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You have "new PrintWriter()" and "close()" inside the loop which will cause the file to be overwritten.
 
Vin Ash
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
if I take the "close" off , the file becomes blank
with it it's actually saving only line 2 but not line 1
Need to know how to make it save all the lines
 
Carey Brown
Saloon Keeper
Posts: 10705
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I didn't say take it off, I said put it outside of the loop.
 
Vin Ash
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
does not work... both my files become blank and nothing is written on screen as well
 
Carey Brown
Saloon Keeper
Posts: 10705
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I made a test file with lines containing a pair of numbers. The code works fine. There is definitely something wrong with either your environment or the way you are running the code. Did you replace print() with println()?
 
Vin Ash
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First of all Thanks Carey
Well I went over what you wrote and the problem was that both files were going blank
(the initial file from which the data was to be taken and the second one where the data was to be written)
I went line by line and could not figure the problem out.
so I tried adapting some of your changes to my old algo and it works to perfection
It reads the original file and does not blank it
it puts the data on screen
and then it saves everything on another file
Thanks and he is the final algo
Now I will continue it because I got to add costs which involves a mathematical equation .I will be working on that now
 
Carey Brown
Saloon Keeper
Posts: 10705
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Glad to be of help.

I might suggest cleaning up your code indentation if you want people on this site to help you. Either tabs (=4spaces), or 4 actual spaces. You have to use them consistently in order for the code formatter to behave correctly.
 
Vin Ash
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok sorry about that .Will try
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic