Avatar of ckawebcreation
ckawebcreationFlag for United States of America

asked on 

remove file writer from class and use bean instead

i have an element of a class i need to remove and put into a bean, see attached code, it is a simple file writer that writes a value to a web page, how do i access this code if it is in another class and would i just use a normal bean class?


try {
BufferedWriter out = new BufferedWriter(new FileWriter(context.getRealPath("updates.txt"), true)); 
out.write(years);
out.close(); } 
					
catch (IOException e) {  System.err.println("error in opertation "); // catch the exception, could stop browser freezing
}

Open in new window

Java

Avatar of undefined
Last Comment
ckawebcreation
ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of ckawebcreation
ckawebcreation
Flag of United States of America image

ASKER

Hi objects,

could i access this from my bean?

(bean.getYears());
Avatar of Mick Barry
Mick Barry
Flag of Australia image

sorry, can you explain further what you are after

Avatar of ckawebcreation
ckawebcreation
Flag of United States of America image

ASKER

sorry objects, getting late, been on this stuff all day!!

i need to implement an MVC architecture, so instead of going into the original class to get the data, i need a bean to sit in the middle that does the try catch stuff in the original post and then i will use a jsp to print the results back to the screen.
Avatar of Mick Barry
Mick Barry
Flag of Australia image

that code is writing to a file, not the screen.
what code is writing to the screen?

Avatar of ckawebcreation
ckawebcreation
Flag of United States of America image

ASKER

sorry objects, got the code mixed up, cheers
Java
Java

Java is a platform-independent, object-oriented programming language and run-time environment, designed to have as few implementation dependencies as possible such that developers can write one set of code across all platforms using libraries. Most devices will not run Java natively, and require a run-time component to be installed in order to execute a Java program.

102K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo