Not a BufferedReader and BufferedWriter a be open at the same time?

For the experienced:

I write a class to selectively extract data from an Excel file and write in a plain text file. I use JDeveloper 11.1.1.3.

It works very well and writes the output as expected file when reading data from the spreadsheet and write directly to the output file.

However, I need to convert data in one column based on a conversion table. The conversion table is a text file that has two columns separated by a space. I read in the conversion table using a BufferedReader and put it in a hash table to use. However, once the buffered reader and the hash table are introduced, the BufferedWriter does no more work.

How the class works are the main() method (not shown here) reads the data from the Excel sheet in a list and then calls the method showExcelData() (as illustrated below) to write the data to the list in a plain text file.

When the green color code has not been added, the output file was written on the drive end. An example of the output file line is:
JOHN:DOE:11223344:12345:20110824
By adding the Green code, I expect the output of the line as:
JOHN:DOE:11223344:STUDENT:20110824
The problem is, after the Green code is added, the output file, the program writes to the disk's size zero.

I added the lines of System.out.println () for troubleshooting. These lines indicate that the BufferedWriter < b > on < /b > is not null, and the conversion is actually underway. But out.write (< b > < /b >) just doesn't work. Commenting on the Green code, the program works again - of course without conversion of the date of this column.

There must be something wrong, but I don't see where it's a mistake.

Your help is very appreciated!


Newman


< pre >
public private static Sub showExcelData (list sheetData, String outputFilename) throws IOException {}
BufferedWriter out = new BufferedWriter (new FileWriter (outputFilename));
System.out.println ("Is Null?" + (out is nothing));
BufferedReader in = null;
for (int i = 3; i < sheetData.size (); i ++) {}
List = (List) sheetData.get (i);
for (int j = 0; j < list.size (); j ++) {}
(HSSFCell) = list.get (j) HSSFCell cell;
If (j == 5: j == 6 | j == 7: j == 11) {}
< font color = "green" > < b >
The column with index 11 is the column of data in need of conversion:
If (j == 11) {}
String convertionFilename = "ConversionTable.txt";
Map < String, String > liveMap =.
new HashMap < String, String > ();
try {}
in = new BufferedReader (new FileReader (convertionFilename));
String line = null;
While ((line = in.readLine ())! = null) {}
String [] keyValue = line.split("");
liveMap.put (keyValue [0], keyValue [1]);
}
} catch (IOException e) {}
String message = e.getMessage ();
}

TitleCode = string
cell.getRichStringCellValue (m:System.NET.SocketAddress.ToString ());

Role of the string = liveMap.get (titleCode) .toUpperCase ();
out. Write (Role);
System.out.println (titleCode + "" + role);
} else {< /b > < / make >}
out. Write (Cell.getRichStringCellValue (). ToString () .toUpperCase ());
System.out.println (Cell.getRichStringCellValue (). ToString () .toUpperCase ()); < font color = "green" > < b >
} < /b > < / make >
If (j < list.size () - 1 & & d! = 11) {}
out. Write(":");
}
} Else if (j == 26) {}
If (cell.getCellType () == HSSFCell.CELL_TYPE_NUMERIC) {}
If (DateUtil.isCellDateFormatted (cell)) {}
Calendar cellDate = Calendar.GetInstance ();
cellDate.setTimeInMillis (cell.getDateCellValue () .getTime ());
String year = ' "+ cellDate.get (Calendar.YEAR);
String = month
Padding (cellDate.get (Calendar.month) + 1);
String = day
Padding (cellDate.get (Calendar.DAY_OF_MONTH));
String expDate = year + month + day;
out. Write (":" + expDate);
}
}
}
}
out. Write (System.GetProperty ("Line.Separator"));
}
If (in! = null) in.close ();
If (out! = null) out.close ();
}
< / pre >

BufferedWriter is, uh, buffered so that you won't see the effect of write() immediately, maybe not until you close the file.

You don't need to open this file to reference and build the card anywhere again for each line. Out of the loop. And you're not close every time you open it, which could cause other problems... and finally you seem to be ignorant of the exceptions. Never do this. You have not actually need the reader and the writer open at the same time, even if this isn't the real problem here.

Tags: Java

Similar Questions

  • How can I open multiple homepages in Firefox? I want that all my Firefox different email accounts open at the same time. I've recently updated to Win7 and now I have to close it and to open Firefox to access another e-mail account!

    I want home pages Firefox 3 separate and distinct for each of my 3 accounts to be open at the same time.

    Questions are usually followed by a question mark. My reply has answered your question.

    Firefox does not have an email, there is no "accounts of Firefox. If you access "electronic mail" with Firefox, you can use web mail. Some web mail services do not allow direct access, they want their users to access their mail from a "portal" or "Home" and will redirect any attempt to load a web site page "internal" return to home page.

    In measure 3 loading different web e-mail accounts at the same time, if they are in the same domain it does not work on Firefox without an addon of Firefox. http://Br.mozdev.org/Multifox/

    IOW, if these three E-mail accounts with Yahoo, without this add-on you would have to connect separately for each e-mail account, log out of the first before logging in the 2nd. Then disconnect the 2nd before logging in the 3rd. Firefox is not able to have several session cookies for a simultaneous connection to the same server. This add-on provides this feature of "multiple sessions cookies".

  • Why I have Photo and Photos open at the same time?

    Why I have Photo and Photos open at the same time?

    When what's going on?  When you connect a camera or a card reader?

    Or after the Mac is restarted?

    If this occurs after startup, check system preferences > users and groups.

    Select your account and open the connection. Deselect the applications you want to open at startup.

    If this happens when you connect a camera, open the iPhoto preferences > general.

    Set the preference "Connecting camera opens" to "no application".

  • j105el envy: envy of hp can not right and made a left click at the same time

    my hp touchpad cant hp envy envy cannot not right and made a left click at the same time. I don't know if it's a driver. because of this I can not play games like GTA cause I need do a right click to aim and left click to shoot. is there a solution to this

    @gwatanaj ,

    Hello and thanks for the display on the HP support forums.  Here is a link that may be useful.

    HP laptops - use and troubleshooting of the TouchPad and ClickPad (Windows 8)

    What you are trying to do may not work with your touchpad.  Normally when it is best to use a mouse.  The hardware is built to be different and you might find it easier to work with.

    If you need help please post back.  First of all, check out this link.

    Tips for the "very best question.

    So, please indicate your model full and product number.

    I hope hear from you soon.

    Thanks again and have a great day.

  • two versions of photoshop open at the same time

    I've updated Photoshop CC last week and now have CC Photoshop and Photoshop CC 2014 in my applications folder. When I open a file created in Photoshop, it opens up Photoshop. However, if I open another Photoshop file (by double-clicking it), it opens a second Photoshop application (instead of the Photoshop application that is already open)... so I have two Photoshops open at the same time. And both are CC versions.

    What gives?

    You must be on a Mac will arrive not under windows. Are you sure that both versions of Photoshop open is CC 14.2.1.  Did you use menu help > about Photoshop since the two windows in Photoshop?

    Read also Re: 14.2.1 CC: minijonction > scripts menu Tools Photoshop launch CC 2014... uh why?

  • On a five year MacPRo, when you try to open a document all stored documents seem to open at the same time, any attempt to stop them results in the cigarette or the seizure of MacPro... of ideas is what the cause/solution?

    On a five year MAcPro, when you try to open a document, all stored documents seem to open at the same time and any attempt to close results in the MacPRo gel for a long period. Ideas for cause and ideas for a solution?

    You have a Mac Pro or a MacBook Pro?

  • How to play stereo mix music and sing in my microphone at the same time?

    Hi guys, need help with Realtek HD audio driver

    I want to play stereo mix music and sing in my microphone at the same time... not for registration but in chat room, say.

    I'm using XP... Toshiba Satellite S4747 laptop
    In the Realtek software "Realtek HD audio input" microphone and two stereo mix... but I can only select one at a time...

    All solutions please thxxxx

    On a different note... a friend of mine using a non-Toshiba laptop with win XP has an older version of the Realtek audio driver and select the mic and stereo mix at the same time... I downloaded this version in my laptop, but still, I can choose only one at a time...

    Check that the audio settings of Windows and don t forget in the Realtek HD audio Manager. You can find it in the control panel.

    I think that your microphone is on Mute check so this.

  • In Windows 7 Action Center, MSE, and Windows Defender convertible 'ON' at the same time?

    In the center of Action of Windows 7, Microsoft Security Essentials (MSE) is enabled.  I tried to turn on Windows Defender 'manually' and get a status of "OFF"OBSOLETE"? that quickly toggles back and forth

    I'm trying to maximize my options "malicious."  I have NOT tried turning 'OFF' MSE to see if Windows Defender will be 'ON '.

    My real question is, can MSE and Windows Defender, being 'ON' at the same time or are mutually?

    A "full scan" using MSE detected the following malicious program "trojan:Win32 / Tracur.AV". I immediately deleted it. I think it's GONE!

    My "quick" weekly scans did not detect this malware. What a scare on my new laptop TOSHIBA P750.

    Now I take the time 'always' do a full scan.

    Help

    Hello

    Welcome to the Microsoft community.

    If you use Microsoft Security Essentials, there is no need to use Windows Defender. You can disable that and just let Microsoft Security Essentials run things.

    You should only use an antivirus program. using several programs at the same time will cause problems.

    Please refer to this link:

    http://answers.Microsoft.com/en-us/protect/Forum/MSE-protect_start/Windows-Defender-and-Microsoft-Security-Essentials/5309cb8d-02e1-40E8-974f-0dcedb9ab9fd

    It will be useful.

    Let us know if you have any questions about Windows and we will be happy to help you.

  • How can you affect multiple windows open at the same time

    How can you affect multiple windows open at the same time

    You can not.  Only a calendar can have several windows.

  • Is it possible to have TWO Wordpad files open at the same time?

    It is possible to have TWO working Wordpad files open at the same time?  I tried 'cutting' nothing doesn't.  With Windows XP, it wasn't a problem...

    Thank you...

    Totally forgot the thing to-do bar, you can also a way to click on it to open a new

  • I can't have multiple files open at the same time! I need to compare the content from one to the other. How to display two files at the same time?

    I can't have multiple files open at the same time! I need to compare the content from one to the other. How to display two files at the same time?

    Hi sindres79946597,

    Open Acrobat Reader DC, navigate to the Edit-> Preferences-> General-> uncheck "Open Documents in the new tab in the same window.

    Now, reboot your system, when you open multiple PDFs that all will open in a new window so that you can easily compare.

    Kind regards
    Nicos

  • Why when I turn on my Mac, the InDesign program open at the same time?

    New problem on my Mac. Why when I turn on my Mac, the CC InDesign program open at the same time? Absently, I probably activated something in the program! Can someone tell me how to disable this feature in Indesign? Thks for helping me!

    Go to System Preferences > users & groups > login items. If InDesign is there, just delete.

  • can't have 2 files open at the same time PS? !!

    I just upgraded to cs3 to cs6.  I open a file photoshop very well, then I click on another PS file so that I can drag a layer from one to the other.  but when I click the second file it opens - but it closes the first file!  This cant be right.  How to make 2 ps files open at the same time?

    User error.

    Just acheck "Documents open as tabs" in Photoshop preferences.

  • opening and reading PDF 2 files at the same time

    Since the last update, I can't open two PDFs at the same time. As soon as I open the second file, the first file is reduced to a minimum.

    Hi sofw.ms,

    Please open Edit > Preferences > General and check "Open document as new tabs.." option to open two PDFs in multiple tabs in the same window.

    Let me know how it goes.

    Kind regards

    Ana Maria

  • How can I have 2 email accounts open at the same time using the apple mail icon?

    How to open 2 e-mail accounts at the same time?

    Hello carroll12,

    Thank you for using communities of Apple Support.

    I see that you do not want to open two e-mail accounts at the same time using the Mail application. I understand perfectly. I have multiple e-mail accounts set up in my Mail application. I'm happy to help you with this.

    You can have more than one e-mail account set up in the Mail application. The first time you open Mail, it may prompt you to add an e-mail account (if you have not already done). Select an account type, and then enter your account information. To add another account, choose Mail > add an account, select an account type, and then enter your account information. Make sure that the Mail check box is selected for the account.

    If you have already both set in place, and I just want to be able to view both on the screen at the same time, open Mail, and then click file at the top.  From there, select the option for the new window of the observer.  This will open a new window where you can see each of the individual mailboxes on the same screen.

    Have an amazing day!

Maybe you are looking for

  • HP 6830: paper photo power supply problem

    When you use Publisher to print a page with pictures and text, my printer HP 6830 seems struggling to feed photo paper.  Printing seems to begin before the paper is introduced by. I tried all possible combinations of settings and yet the sheet comes

  • double drive bays

    Salvation, of which 15.6 laptop in range of HP have space for 2 hard drives without removing the DVD. As is - one of the portable beaches are supported 32 GB of ram?

  • I can't add my Nikon SLR as a device. Help?

    I installed the Nikon software provided with Nikon Coolpix L22.  I can't transfer my pictures from the camera to the computer.  I have the USB cable plugged in but nothing happens.  When I look at the devices, I don't find a way to add the camera to

  • Camera.h - Autofocus assist light

    Hello everyone! I developed an application that takes pictures using the C++ API camera.h: https://developer.blackberry.com/native/reference/core/com.qnx.doc.camera.lib_ref/topic/overview.htm... I disabled the flash, but the LED still flashes in the

  • Facility not up to date

    I just got help to re - install indesign and it's old. When I uninstalled was new.