New to java...  Having problems with Stringbuffer - FileReader

I believe what I am trying to do is quite simple but I am missing something...
Basically I need to read the contents of a text file and append the text to an email message. As I said, I am new to java and I certainly don't understand everything, but I will do my best to answer any questions you may have.
My attempt at writing the code is below. The relevant sections are in bold
private void emailDevLicense(HttpServletRequest request, HttpServletResponse response, String operatorId) {
String configId = request.getParameter("configurationId");
String deployPath = cdlcmConfig.getLmLicensePath();
String cName = request.getParameter("cName");
String aName = request.getParameter("aName");
String lPath = request.getParameter("lPath");
String licenseName = request.getParameter("name");
String description = request.getParameter("licenseConfigDesc");
String contents = null;
Properties emailProperties = new Properties();
emailProperties.put("mail.smtp.host", cdlcmConfig.getEmsMailServer());
Session mailSession = Session.getDefaultInstance(emailProperties, null);
String mailFrom = cdlcmConfig.getEmsMailFrom();
MimeMessage message = new MimeMessage(mailSession);
MimeBodyPart p1 = new MimeBodyPart();
MimeBodyPart p2 = new MimeBodyPart();
MimeBodyPart p3 = new MimeBodyPart();
String operatorName = DbHelper.getOperatorName(operatorId);
String recipient = "[email protected]";
String filename1 = deployPath + "/l-" + configId + "/license.dat";
String filename2 = deployPath + "/l-" + configId + "/company.dat";
log.info("emailDevLicense");
*try {*
File f = new File(lPath, "license.dat");
BufferedReader br = new BufferedReader(new FileReader(f));
StringBuffer sb = new StringBuffer();
String eachLine = br.readLine();
*while (eachLine != null) {*
eachLine = br.readLine();
sb.append(contents); }
*catch (java.io.FileNotFoundException ex) {*
log.error("Unable to find license file license.dat", ex);
*catch (java.io.IOException ex) {*
log.error("Unable to read lines from license.dat", ex);
try {
/* Set user-entered RFC822 headers to a message (mmsg). */
message.setHeader ("From", "[email protected]");
message.setHeader ("Reply-To", "[email protected]");
message.setHeader ("To", recipient);
message.setSubject("License files for Customer Name: " + cName + " / Account Name: " + aName + "");
/* Add any other desired headers. */
p1.setText("Configuration Name: " + licenseName + "\n\nOrder Number: " + description + "" + contents + "");
// Put a file in the second part
FileDataSource fds1 = new FileDataSource(filename1);
p2.setDataHandler(new DataHandler(fds1));
p2.setFileName(fds1.getName());
// Put a file in the second part
FileDataSource fds2 = new FileDataSource(filename2);
p3.setDataHandler(new DataHandler(fds2));
p3.setFileName(fds2.getName());
// Create the Multipart. Add BodyParts to it.
Multipart mp = new MimeMultipart();
mp.addBodyPart(p1);
mp.addBodyPart(p2);
mp.addBodyPart(p3);
// Set Multipart as the message's content
message.setContent(mp);
log.info("Sending Dev License");
Transport.send(message);
} catch (MessagingException ex) {
log.error("Unable to send license mail to address " + recipient, ex);
}

You guys\gals rock...
This solved my problem and taught me something in the process. I have been trying to do this myself for 3 days now...so...thanks so much for the help.
Once that worked I had to add a return after each line was read and I actually got that right on the first try.
The final code is below.
Thanks everyone..
try {
            File f = new File(lPath, "license.dat");
            BufferedReader br = new BufferedReader(new FileReader(f));
            StringBuffer sb = new StringBuffer();
            String eachLine = br.readLine();
            while (eachLine != null) {
                sb.append(eachLine + "\n");
                eachLine = br.readLine();
           contents = sb.toString();
            catch (java.io.FileNotFoundException ex) {
            log.error("Unable to find license file license.dat", ex);
            catch (java.io.IOException ex) {
            log.error("Unable to read lines from license.dat", ex);
            }

Similar Messages

  • The new Firefox is having problems with imd

    the new Firefox is having problems with imd

    This is a duplicate. See -
    https://support.mozilla.com/en-US/questions/834031

  • New to java, having trouble with classes

    I am new to java and I am having problems importing classes in my first program, please help

    hi
    please tell, what`s your problem exatly?

  • New to JDeveloper, having problems with EJB tutorial.

    Hi,
    I'm new to the world of JDeveloper, I'm trying to follow this tutorial
    http://st-curriculum.oracle.com/obe/jdev/obe11jdev/ps1/ejb/ejb.html
    Firstly when I create an entity from a table I get the following error;
    Starting Offline Database Synchronization
    Generating classes for Entity CbsdSecurity...
    Entity generation for CbsdSecurity failed.
    I'm not really sure why this is, however I suspect this is at the heart of the problems.
    If I continue I can get to the point where I create a EJB Diagram, however when I try to drag my autogenerated class onto the diagram I get the following error;
    "Entity does not belong to Persistence Unit xxxxEJB which is associcated with Diagram EJB3.ejb_diagram"
    In addition the log at the bottom has the following warnings.
    23-Sep-2010 10:07:46 oracle.security.jps.internal.credstore.ssp.CsfWalletManager openWallet
    WARNING: Opening of wallet based credential store failed. Reason java.io.IOException: PKI-02002: Unable to open the wallet. Check password.
    23-Sep-2010 10:07:53 oracle.adf.share.jndi.ReferenceStoreHelper getReferencesMapEx
    WARNING: Incomplete connection reference object for connection:fcs2ukd
    Now my database connection doesn't seem to remember the password even though I have ticked the 'remember password' tick box.
    I am developing under Windows XP using JDK1.6.0.21
    If anyone could point out what I'm going wrong I would be very grateful.
    Thanks
    Rich
    Edited by: Rich Carless on Sep 23, 2010 9:32 AM

    Try to test Your DB connection in JDeveloper. Is it success?
    Best regards, Debuger!

  • HT204053 I created a different Apple ID for Icloud on my new IPhone and having problems with getting Itunes,etc.  How do I change my Icloud Apple ID to be the same ID and password?

    I created a different Apple ID for my Icloud on my new IPhone (said a free email was available or something similar) rather than the other choice offered of using my same existing Apple ID.  Now I keep having issues accessing my account and my password isn't working to access Icloud to download Itunes.  Can I undo this new account I created and just use my one existing Apple ID?  This is my first IPhone and confused with this part of the setup!  Thanks.

    If you know the answers to your security questions, you should be able to change your password without using email authentication (see http://support.apple.com/kb/HE36).  If you don't, you may be out of luck.

  • New to java, having trouble with Installing JDK on Ubuntu

    Hello, everyone???
    I'm try to install j2se jdk-1_5_0_15-linux-i586-rpm.bin on my Ubuntu Linux 7.10, I ran the self-extract file and everything just seemed fine. But when I get to setting the system environment variable , something must have gone wrong. I have read from books which say that I should set 'CLASSPATH=.:/usr/java/jdk1.5.0_15/lib/dt.jar:/usr/java/jdk1.5.0_15/lib/tools.jar'. But I can't find a 'tools.jar' file in the 'lib' directory. There is a 'tools.pack' instead of it.
    When I try to test the installation with: 'javac --version', I got :
    Error occurred during initialization of VM
    java/lang/NoClassDefFoundError: java/lang/Object
    I don't know why. Do anybody can help me with this problem?

    I used the Synaptic version of Java. I don't like where it puts the JDK in a protected folder. I want development stuff in my home folder. The Sun download with the NetBeans is the best, IMHO. You put your install where you want it. NetBeans then slams the pathname with every javac and java you run. Works great for development. Then, becomes the FireFox problem -- the java plug-in. Because I'm AMD-64 I have to use the IceTea java plug-in.
    Would Sun please, please write the 64-bit plug-in?
    The last irritating problem you will have is running java from a Terminal. That takes internal links in your File System. You can do what NetBeans does: java -classpath=~home/desktop/jdk1.6.1/bin/myPrograms myProgram. Or, you can make SymLinks. I keep a bookmark to this topic from the Ubuntu Forums:
    [Custom Install JDK java|http://ubuntuforums.org/showthread.php?t=319138]

  • New to Jdev: having problem with Helloworld class and the jsp

    Please, i went through the beginner's tour at oracle site and it has been interesting.
    After putting the class name as Hello, the package name as "mypackage1" as in the example, then the extend field as java.lang.object There is always an error saying that "java.lang.object is not a valid base class for this option". Please what can i do, cos it's delaying my practise.
    secondly, practising the jsp stuff is also interesting, but it's not showing the web preview. i mean after designing the stuff myself, it's giving some compilation error.
    What can I do.
    Thanks

    Hello,
    1- Are you running the "Building Your First Program with JDeveloper 10g" located at
    http://www.oracle.com/technology/obe/obe9051jdev/FirstStep/FirstStep.htm
    If not, is it working for you ?
    2- Which exact version of JDeveloper are you running ? (Help -> About)
    You should be running JDeveloper 10.1.2.x.x
    You can get Oracle JDeveloper 10g (Version 10.1.2.1, build 1913) at
    http://www.oracle.com/technology/software/products/jdev/index.html
    look for the chapter "Oracle JDeveloper 10g Production".
    3- Try re-installing JDeveloper (uncompressing the zip file) into a different
    path (ex: C:\JDeveloper10g) and retry the first steps.
    I've retested the "First Steps" against my Windows XP SP2 and it works just fine.
    Regards,
    Steff

  • Can I get back my previous vrsion of firefox? The new one is having problems with my most used site.

    CafeWorld on facebook. Certain features are a problem. The older firefox version was better with this.

    To revert to the previous secure version, please do the following.
    * Go to [http://www.mozilla.com/en-US/firefox/all-older.html Download Firefox v3.6.17] and download it to the desktop.
    * Then go to Add/Remove Programs, scroll down to "Mozilla Firefox" and remove it, choosing to keep your bookmarks, customizations etc., (''don't checkmark the box'').
    * Then reboot and delete the folder called "Mozilla Firefox" at this location: C:\Program Files\Mozilla Firefox
    * Finally run the installation file you downloaded to the desktop earlier.
    Your bookmarks, customizations etc., are maintained in a different location and will become available to you again once you complete the installation.
    After you downgrade, update these two plugins.
    * Adobe Flash via http://get.adobe.com/flashplayer/
    * Adobe Shockwave For Director via http://get.adobe.com/shockwave/
    The version of Flash you have installed at the moment is a security risk. See http://www.adobe.com/support/security/advisories/apsa11-02.html

  • I am having problems with my music collection, after burning all of my music to the computer I organized it into folders and placed it in the iTunes Folder. Starting on a new computer now. I can get my music from old computer?

    I am having problems with my music collection, after burning all of my music to the computer I organized it into folders and placed it in the iTunes Folder. As of now i realize this was a mistake. Starting on a new computer now. I cant get my music to transfer from the itunes folder on the old computer? I keep getting error "Can't Read from the source file or disk." Whenever I got to folder properties its always checked read only. But when i play the song it works just fine. Im sure this is just because I added music into itunes folder but is there anyway to fix it?

    WMA files are 'window media audio' files, which is a Microsoft format. If you want to add them to your iTunes library on your Mac then you will need to convert them into a compatible format first. If you still have your windows machine then iTunes for Windows can convert them from WMA to MP3 format : https://discussions.apple.com/message/24158701#24158701
    Or try a search for, for example, 'convert wma to mp3' to find programs to convert them.

  • I had already update mi new factory unlocked iPhone 4S to iOS 5.1.1 and I still having problems with "invalid sim". I'm from Argentina and here we don't have official service. PLEASE HELP ME, WHAT CAN I DO??? In Argentina is too expensive an iPhone 4S.

    I had already update mi new factory unlocked iPhone 4S to iOS 5.1.1 and I still having problems with "invalid sim". I'm from Argentina and here we don't have official service. PLEASE HELP ME, WHAT CAN I DO??? In Argentina is too expensive an iPhone 4S. Please I need help to continue believing in Apple. Thanks a lot. If anybody speak spanish better.  

    Was it purchased from an official Apple Store, not a reseller?  Only Apple Stores sell official factory unlocked phones.  The others sell hacked to unlock phones, and the unlocking is unstable.
    Try these steps, as needed:
    1. Reset phone - press both home and on/off buttons for at least 10 seconds until the Apple logo appears.
    2. Settings > General > Reset > Reset Network Settings.
    3. Replace SIM card (and reset network settings again)
    4. Restore Phone in iTunes using a backup
    5. Restore in iTunes as new, without using a backup

  • Can you help I was having problems with my iPod so I restored it but I accidentally set it up as a new iPod is there any way to restore it from an old  backup when I right click iPod in iTunes there isn't one anyway to recover one or find it on computer

    Hi can you help I was having problems with my iPod so I restored it but I
    accidentally set it up as a new iPod is there any way to restore it from an old
    backup when I right click iPod in iTunes there isn't one anyway to recover one
    or find it on computer

    The following says how to restore from backup.
    iOS: How to back up
    If you go to iTunes>Preferences>Devices you can see if you have an iTunes backup. You need one dated before or the exact time you started the restore.

  • Is anyone having problems with the new Xerox printer driver update from Apple? My 8700S is no longer working with QuarkXPress.

    I allowed a System Update that included a Xerox Printer update. I am running a MacPro 10.6.8 with Quark 8.5.1 and a Xerox ColorQube 8700S.  EVERY was working perfectly before the "update" but afterwards anything sent to the printer from Quark would stall the printer.  I went to the Xerox website and downloaded their Printer Driver and tried again.  Now I could print from  Quark but I can NOT get to the printer window to change the type of paper, etc.  So, the problem still persists.
    Should I try going into Time Machine and trying to find the Xerox Print Driver in the Library folder?
    Should I upgrade the whole system software?  (I wouldn't mind doing that AFTER I get this magazine off to the commerical printer)
    Should I upgrade to Quark 9?
    Any help here would be apprciated.
    Thanks  - Rob

    As a general rule of thumb, I never install updates until I read its info and I am having problems with my current software.  I hide the updates until I need them.  Usually this happens when I update or upgrade my os.  I don't fix what ain't broken is my golden rule.
    It is possible that you need to update or upgrade Quark in order for your newer printer driver to work.  First I would try the following....
    Disconnect all peripherals from your computer.
    Boot from your install disc & run Repair Disk from the utility menu. To use the Install Mac OS X disc, insert the disc, and restart your computer while holding down the C key as it starts up.
    Select your language.
    Once on the desktop, select Utility in the menu bar.
    Select Disk Utility.
    Select the disk or volume in the list of disks and volumes, and then click First Aid.
    Click Repair Disk.
    Restart your computer when done.
    Repair permissions after you reach the desktop-http://support.apple.com/kb/HT2963 and restart your computer.
    If your printer does not work afterwards, update or upgrade Quark.  If that does not work, contact the printer manufacturer.

  • Hi am having problems with iTunes,I have all my music on my 4s but I bought the iPhone 5 today.us there any way that I can transfer music over to my new phone without using the library?as it doesn't seem to be on my PCM anymore.

    Hi am having problems with iTunes,I have all my music on my 4s but I bought the iPhone 5 today.is there any way that I can transfer music over to my new phone without using the library?as it doesn't seem to be on my PC anymore.i reset my pc and save my iTunes to a hard drive but can't access it.Need help please

    " When I did this, my library showed all the music I have "purchased" from itunes but did not have the music that I downloaded a long time ago through itunes from my old CDs."
    Correct.
    " How can I get that music to show up in my library now on my new computer?  "
    Copy it from your old computer or your backup copy of your old computer.
    The sync is one way - computer to ipod.

  • Having problems with ipad mini and Siri. Works sporadically, will work once and then the second time not. Worked all the time with the original Mailbox app. Then started doing the same thing when I installed the new update so wondering if it is software?

    Having problems with ipad mini and Siri. Works sporadically, will work once and then the second time not. Worked all the time with the original Mailbox app. Then started doing the same thing when I installed the new update so wondering if it is software?

    Hi,
    I have the check box on a second Partition  but not on the Time Machine one
    I forget what I did now to get this called "Recovery HD"
    For the rest try https://discussions.apple.com/docs/DOC-4055  User Tip that links to Pondini's work on Time Machine.
    10:17 pm      Friday; May 2, 2014
    ​  iMac 2.5Ghz i5 2011 (Mavericks 10.9)
     G4/1GhzDual MDD (Leopard 10.5.8)
     MacBookPro 2Gb (Snow Leopard 10.6.8)
     Mac OS X (10.6.8),
     Couple of iPhones and an iPad

  • I just updated to new final cut pro x 10.1.1 and i am also on mavericks so but on my editing timeline i was trying to color grade using magic bullet looks but i am having problem with it. when it comes back to tcp x it's black.

    I just updated to the new final cut pro x 10.1.1 and i am also on mavericks so but on my editing timeline i was trying to color grade using magic bullet looks but i am having problem with it. When i send a sample to MBL and color grade it , it comes back to final cut pro x all black even after render. By the way on the MBL i am using the GPU rendering, I used before like 4months ago and it was fine. And i don't like to use the CPU because it very slow.

    What is the frame rate of the project? At what frame rate was the media recorded? What frame size?
    What are the audio settings?
    What are the specs of the machine, in particular how much RAM, how is the hard drive connected, etc.?
    If possible, post screenshots of the inspector for the project.
    It could be related to the audio frequency?

Maybe you are looking for