Can't a BufferedReader and a BufferedWriter be open at the same time?

To the experienced:
I am writing a class to selectively extract data from an Excel file, and write out to a plain text file. I am using JDeveloper 11.1.1.3.
It works fine and writes out the output file as expected when reading data from the spreadsheet and directly writing to the output file.
However, I need to convert the data in one of the columns based on a conversion table. The conversion table is a plain text file that has two columns separated by a space. I read in the conversion table using a BufferedReader and put it in a HashMap for use. However, once the Buffered Reader and the HashMap are introduced, the BufferedWriter does not work any more.
The way the class works is that, the main() method (not shown here) reads data from the Excel sheet into a List, and then calls the method showExcelData() (as shown below) to write out data from the List to a plain text file.
When the green color code was not added, the output file was written to the disk fine. A sample line from the output file is:
JOHN:DOE:11223344:12345:20110824By adding the green code, I expect it to output the line as:
JOHN:DOE:11223344:STUDENT:20110824The problem is, after the green code is added, the output file the program writes to the disk is zero size.
I added the System.out.println() lines for troubleshooting. These lines show that the BufferedWriter <b>out</b> is not null, and the conversion is actually taking place. But <b>out.write()</b> simply does not work. Commenting out the green code, the program is working again - of course, without date conversion for that column.
There must be something wrong but I can not see where it is wrong.
Your help is very much appreciated!
Newman
<pre>
private static void showExcelData(List sheetData, String outputFilename) throws IOException {
BufferedWriter out = new BufferedWriter(new FileWriter(outputFilename));
System.out.println("Is out null? " + (out == null));
BufferedReader in = null;
for (int i = 3; i < sheetData.size(); i++) {
List list = (List)sheetData.get(i);
for (int j = 0; j < list.size(); j++) {
HSSFCell cell = (HSSFCell)list.get(j);
if (j == 5 || j == 6 || j == 7 || j == 11) {
<font color="green"><b>
// The column with index 11 is the column of data that needs 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();
String titleCode =
cell.getRichStringCellValue().toString();
String role = liveMap.get(titleCode).toUpperCase();
out.write(role);
System.out.println(titleCode + " " + role);
} else {</b></font>
out.write(cell.getRichStringCellValue().toString().toUpperCase());
System.out.println(cell.getRichStringCellValue().toString().toUpperCase());<font color="green"><b>
}</b></font>
if (j < list.size() - 1 && j != 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>

Hi, All,
This posting is at the bottom of the stack. Quite a few more postings were added on top of this and solved, and now I reach back to this one.
The main problems are:
1. Close the I/O buffer after finishing using it. Otherwise the data in the buffer do not get flushed to the file on the disk. I think that is the cause of the problem of getting zero sized output file.
2. Do not count on Excel to stop at a blank cell by using Ctrl-down / Ctrl-up. The file I am processing is produced by some reporting program which, I think, instead of skipping the cell, puts a zero-sized string in it. Obviously, Excel does not stop at such cells. I had checked the columns using the Ctrl-down/Ctrl-up key and through that column did not have blank cells. Sharp-eyed gimbal2 spotted the problem, and led me to re-inspect the column by using up/down arrow keys instead, and found the blank cells. Such empty strings are used in my code as key in searching the map (String role = liveMap.get(titleCode).toUpperCase();) and caused the problem.
And the lesson is, when doing some quick and dirty tests, do not get too quick and too dirty, which can end up slower rather than faster.
Many thank to all of you for giving me the helping hand!
Newman

Similar Messages

  • Help I can only have max. 3 osx apps. open at the same time ?

    Help I can only have max. 3 apps. open at the same time ?
    If I have 3 apps. open, and try to open a 4th. this message comes up :
    The application "Mail" cannot be launched. -10810
    Of cause if I'm trying to open up something else than mail, lets say iPhoto, it will say "iPhoto".
    This is very weird to me, and I'm normally pretty good at solving issues myself, but I'm stuck with this one.
    Please help out

    I've had this quite a lot too. Do you find that under these conditions you can't load a disk image either?
    At first I put this down to Rosetta taking up a lot of resources. I was running OmniWeb with a lot of pages open in the workspaces so I've switched back to Safari until OmniWeb is UB. This morning I read that having Windows file sharing switched on helps to cause this problem. I switched this off, rebooted and ran disk utility to repair disk permissions and I've been running OK since then. I've currently got 13 apps open plus Finder and Widgets. They include 2 bigguns, Eclipse/MyEclipse and Visual Paradigm for UML. It'll probably stop working now I've written that.
    I run a MBP 17 with 2GB memory. My guess is that Windows file sharing does cause problems. I just hope Apple has resolved this in 10.4.7... whenever that is.
    Gareth

  • Can't play music and be on old network at the same time?

    I just want to use this device to play music and connect to my original wireless network. I assume since I'm not using an Airport Extreme to connect to the internet then I can't get the Airport Express to connect either. I can't listen to music and be online at the same time the way it is currently configured. Is there another way to set this up so I can connect to my airport on itunes and play music while being on my other wireless network?

    Try Doing a hard Reset your Express and go through the setup procedure again.
    This time making sure your joining your existing network.
    Powerbook G4, MacBook Pro, Mac G5, Mac G4, Mac Mini   Mac OS X (10.4.8)  

  • HT4437 Can't get iTunes and monitor mirroring to work at the same time.

    When I turn on my airplay on itunes it turns off the airplay from my monitor. I don't know how I've done it before but I sometimes can't play itunes and have it mirror my screen at the same time so I can use the visualizer. Whenever I turn one on, the other shuts off. I've done it before. Is there a specific sequence you need to run itunes and have the mirroring work too?
    Ak

    You might try a simple headphone splitter like this:
    http://www.amazon.com/Belkin-F8V234-WHT-APL-Headphone-Splitter/dp/B0000UV2AW

  • WRT110 Can't connect MAC and PC to wireless network at the same time.

    I installed a WRT110 router on my son-in-law's MAC sometime back and at the time configured it to have the MAC connected via Ethernet.  My PC laptop worked fine with it in the wireless mode.  Recently we changed the MAC to wireless newtworking and removed the Ehthernet connection.  Now if the MAC connects to the wireless network first and then I attempt to connect with my PC laptop the PC cannot find the network and the MAC loses connection.  If I shut my PC down the MAC will not find the network until it is put to sleep and reawakened.  If the MAC is put to sleep my PC wil immediately find the network. If I first connect my PC and then awaken the MAC both work fine.  I've checked all of the router's setup settings and they seem to be OK.  I am not MAC savvy and my son-in-law is a neophyte at computers so we are really helpless when something doesn't work.  Help will be appreciated. 

    I tried this setup change after reading another similar post.  It didn't help.  One thing I had wrong in the first post is that neither computer will connect to the wireless net after we experience the wireless failures until both are turned off, at least that is what happened after making the suggested changes.  Is this a WRT110 issue?  Seems there are quite a few posts similar to mine. 
    Bo2

  • I was backing up my iPhone and importing photos onto iPhoto at the same time , then suddenly it says no more space available (i had 48GB before i do this and now i have 18GB) i can't find the back up or the photo anywhere , how can i delete them ?

    i was backing up my iPhone and importing photos onto iPhoto at the same time , then suddenly it says no more space available (i had 48GB before i do this and now i have 18GB) i can't find the back up or the photo anywhere , how can i delete them ? i dont need the pictures or the back ups , i want to delete them but they are not there

    Empty the Trash if you haven't already done so. If you use iPhoto, empty its internal Trash first:
    iPhoto ▹ Empty Trash
    Do the same in other applications, such as Aperture, that have an internal Trash feature. Then reboot. That will temporarily free up some space.
    According to Apple documentation, you need at least 9 GB of available space on the startup volume (as shown in the Finder Info window) for normal operation. You also need enough space left over to allow for growth of the data. There is little or no performance advantage to having more available space than the minimum Apple recommends. Available storage space that you'll never use is wasted space.
    When Time Machine backs up a portable Mac, some of the free space will be used to make local snapshots, which are backup copies of recently deleted files. The space occupied by local snapshots is reported as available by the Finder, and should be considered as such. In the Storage display of System Information, local snapshots are shown asBackups. The snapshots are automatically deleted when they expire or when free space falls below a certain level. You ordinarily don't need to, and should not, delete local snapshots yourself. If you followed bad advice to disable local snapshots by running a shell command, you may have ended up with a lot of data in the Other category. Reboot and it should go away.
    See this support article for some simple ways to free up storage space.
    You can more effectively use a tool such as OmniDiskSweeper (ODS) to explore the volume and find out what's taking up the space. You can also delete files with it, but don't do that unless you're sure that you know what you're deleting and that all data is safely backed up. That means you have multiple backups, not just one.
    Deleting files inside an iPhoto or Aperture library will corrupt the library. Any changes to a photo library must be made from within the application that created it. The same goes for Mail files.
    Proceed further only if the problem isn't solved by the above steps.
    ODS can't see the whole filesystem when you run it just by double-clicking; it only sees files that you have permission to read. To see everything, you have to run it as root.
    Back up all data now.
    If you have more than one user account, make sure you're logged in as an administrator. The administrator account is the one that was created automatically when you first set up the computer.
    Install ODS in the Applications folder as usual. Quit it if it's running.
    Triple-click anywhere in the line of text below on this page to select it, then copy the selected text to the Clipboard by pressing the key combination command-C:
    sudo /Applications/OmniDiskSweeper.app/Contents/MacOS/OmniDiskSweeper
    Launch the built-in Terminal application in any of the following ways:
    ☞ Enter the first few letters of its name into a Spotlight search. Select it in the results (it should be at the top.)
    ☞ In the Finder, select Go ▹ Utilities from the menu bar, or press the key combination shift-command-U. The application is in the folder that opens.
    ☞ Open LaunchPad. Click Utilities, then Terminal in the icon grid.
    Paste into the Terminal window (command-V). You'll be prompted for your login password, which won't be displayed when you type it. You may get a one-time warning to be careful. If you see a message that your username "is not in the sudoers file," then you're not logged in as an administrator.
    The application window will open, eventually showing all files in all folders, sorted by size with the largest at the top. It may take a few minutes for ODS to finish scanning.
    I don't recommend that you make a habit of doing this. Don't delete anything while running ODS as root. If something needs to be deleted, make sure you know what it is and how it got there, and then delete it by other, safer, means. When in doubt, leave it alone or ask for guidance.
    When you're done with ODS, quit it and also quit Terminal.

  • Can I use more than one blue-tooth device at the same time on IPhone 4S? Like a wireless headsets and speed and cadence sensor for cycling computer, receive the data and listen music simultaneously

    Can I use more than one blue-tooth device at the same time on IPhone 4S? Like a wireless headsets and speed and cadence sensor for cycling computer, receive the data and listen music simultaneously

    As long as the profiles are different (ex. HID vs AD2P) you will not have any issues. But say if you try to use 2 keyboards at once, it won't work. Or 2 headsets at once. Your scenario seems fine.

  • I am doing two people's jobs and I need to use two separate log-ins on the same website. How can I keep both log-ins open at the same time. Everytime I switch tabs I have to log in again.

    I am doing two people's jobs and I need to use two separate log-ins on the same website. How can I keep both log-ins open at the same time. Everytime I switch tabs I have to log in again.

    Try one of these extensions for multiple cookie sessions.
    Multifox: <br />
    http://br.mozdev.org/multifox/ <br />
    Cookie Swap extension: <br />
    https://addons.mozilla.org/firefox/3255/ <br />
    Cookie Pie extension: <br />
    http://www.nektra.com/oss/firefox/extensions/cookiepie/

  • Can you use apple tv to play a movie on your tv (say for kids to watch) and use your mac book at the same time to browse the internet ???

    Using a mac book pro !
    Can you use apple tv to play a movie on your tv (say for kids to watch) and use your mac book at the same time to browse the internet ???

    Good question bigboggerchoot.  I also would like to know the answer to this.

  • Phone and my husbands iphone ring at the same time when only one of us is being called. How can I stop this from happening?

    Both my iphone and my husbands iphone ring at the same time when only one of us is being called. How can I stop this from happening?

    This post has already been answered. Why are you plugging your own site with an answer that has already been given? Not to mention that the information you are handing out is incorrect. There is no bug, there is no patch, and no one needs to delete any email addresses. If you take the time to read the posts with the correct answers, you will see that the solution is totally different than the erroneous one you have posted.
    GB

  • Can I have mail and contacts open at the same time

    I really want to be able to have one or more iCloud Apps open at the same time; for example, I may be looking up some info on a contact or in calendar in order to mail someone. At times I have just opened a different tab, but it seems that iCloud then gets messed up.
    I am running Windows 7 at work and the latest version fo Chrome.
    Any help would be greatly appreciated.
    Bryan

    Hi,
    I don't know in Chrome, but in Safari (pc or mac) you can open icloud.com twice on two different tab or windows and open one with contact and the other in Mail without messing up.  What kind of mess to do you experience?
    There is no other options to do what you want to do.  You need to click on the little top cloud to switch from one to another.
    Beside, I don't understand why even 2 open tab would help more than having to switch via the cloud icon.  I may need to cut/paste some info from contact or calendar from time to time, but switch via the cloud icon is not really painfull.

  • One SIMPLE, SIMPLE question that the answer seem to be no whre IN PLAIN ENGLISH! What do you have to do to have two of more tabs open at the same time. Just like ANY OTHER BROWSER LETS YOU DO! Ya know....so you can drag and drop things like pics etc.

    For Pete's sake. This is not rocket sience. What more details do you want. I want two tabs OPEN at the same time so I can copy from one to the other or drag and drop from one to the other.

    You can copy text and hover that selected text with the left mouse button down on another tab on the tab bar until that tab opens and drop the text in a text field in that tab. You need to make sure that that text area is visible because you can't scroll the page. You can also tear off that tab (temporarily) to a new window and resize them to see both windows. Move the tab back to the other window once you are done if you prefer that.

  • When i have 4 or 5 browser windows open at the same time, sometimes they get grouped into one tab and i can not ungroup them. why does this happen?

    4 or 5 browser windows open at the same time. Tabs are down in the control bar. every now and then they just combine into one pop up. can't undo and very annoying. Have to close all out and start over.

    This can happen if you drag a tab slightly down in the browser window while clicking.
    Firefox has a feature called tear-off tabs
    You can detach a tab from the current window and open it in a new window by dragging a tab in the browser window.
    You can also do this via the right-click context menu of a tab: Move to New Window
    You can drag that tab back to the tab bar in the original window to undo that detaching.
    * https://addons.mozilla.org/firefox/addon/bug489729-disable-detach-and-t

  • How can I share applications and softwares with different users of the same computer?

    First question: How can I share applications and softwares with different users of the same computer?
    Second : Can I use 2 different I cloud accounts to synt 2 iphones with one computer?

    Applications installed on the admin account are available to all user accounts unless Parental Controls are enabled.
    Yes.   Separate user accounts, help here >   How to use multiple iPods, iPads, or iPhones with one computer

  • I have an Iphone 6 plus. Can the bluetooth connect to the cars speaker system and a Garmin HUD unit at the same time?

    I have an Iphone 6 plus. Can the bluetooth connect to the cars speaker system and a Garmin HUD unit at the same time?

    Hi,
    Normally yes, Bluetooth can connect to multiple devices at the same time, so yes.
    The only thing is that you'll be able to send sound/music to only one at a time, but I understand the Garmin HUD doesn't play sounds.
    cheers

Maybe you are looking for

  • Major iPod Problems! Please help!

    Recently, my iPod was running very slugish. The videos would skip and take a very long time to load, and then sometimes my menus would freeze or seem to take longer than expected to change. My friend told me that I should reset it by pressing the Men

  • How to get the reference of the component JSF by the faces context

    I have : <h:commandLink id="toto" action="#{controller.test}" > I want to get the reference of this commandLink component in function test of "controller ", for instance , to get the "id" attribute of it, so how to do it? by facescontext?????? Thanks

  • Internet explorer and Safari

    I cannot get on the internet using either IE or safari. I get this message " The application explorer has unexpectedly quit" same for Safari. Please help Darly

  • Need update windows 8 nokia 1520 phone flash player

    Need update windows 8 nokia 1520 phone flash player

  • Seperador decimal en fichero de texto

    Buenas Estoy tratando de leer un fichero de datos generados con LabView ( curvas.txt). Si leo el fichero desde el VI lo hace correctamente, sin embargo lo hago desde el ejecutable se come los decimales. Puede alguien echarme una mano? Gracias Attachm