Get File Size problem

Hi,
I am using a BufferedWriter to write into a file, and I need to monitor the file size. If the file exceeds certain size, then I need create another file. Here is my code:
File file = new File ("myname");
file.createNewFile();
BufferedWriter bwr = new BufferedWriter (new FileWriter());
while (my conditions...)
System.out.print (file.length());
if (file.length > 1000)
bwr.close();
file = new File("anothername");
file.createNewFile();
bwr = new BufferedWriter (new FileWriter(file));
bwr.write("msg");
bwr.newLine();
Although from the file system, I found the file has been over 17K, but the application although print 0 as the file.length(). Is there anything I did wrong?
Thanks!

I suspect the problem is because your creating a new file and then writing to it. And to make it even more fun, your using a buffered writter, so who knows whats going on behind the scenes. Using a new File object may do the trick, but i doubt it.
Is there any reason why you dont count what you have written? its a new file and you know what your writing, so just calculate what you have written so far.
The other option is to use RandomAccessFile. You would use getFilePointer() which returns the offset in the file your up to.
James.

Similar Messages

  • Can't get file size, possibly because of charset problem

    I have an application that needs to recursively find directory sizes, I have a class extending java.io.File with an internal method to do this:
    private static long getSize(File file) {
                    long size = file.length();
                    if (file.exists()) {
                            if (file.isDirectory()) {
                                    File[] files = file.listFiles();
                                    for (int i = 0; i < files.length; i++) {
                                            size += getSize(files);
    } else {
    System.out.println("Problem checking size on \"" + file + "\", reported file size is: " + file.length());
    return size;
    It works (matches du -b output) with the exception of some problematic files I have.
    Output from ls:
    $ ls -l
    total 5461
    -rw-r--r--  1 xyz users    1003 Feb 16 22:06 FileWRS.class
    -rw-r--r--  1 xyz users     831 Feb 16 22:04 FileWRS.java
    -rw-r--r--  1 xyz users     489 Feb 16 22:07 FolderSizes.class
    -rw-r--r--  1 xyz users     198 Feb 16 21:23 FolderSizes.java
    -rwxrwxrwx  1 xyz users 5568138 Apr 25  2004 test.?.abcOutput from du -b:
    $ du -b
    5583203 .Output from my code:
    $ java FolderSizes .
    Problem checking size on "./test.?.abc", reported file size is: 0
    15065The character displaying as "?" is actually an accented e character ("�") and displays correctly in konqueror (my gui file browser).
    I don't really know why it can't pick up the character, but I'm more interested in just getting the file size and ignoring the character problem, any solutions/suggestions for places to look? Do I need to supply more information?

    Try:
    LC_ALL=en_US.ISO8859-1 java FolderSizes .
    Does this help?Yes, that does fix it for my terminal, but if possible I would like a solution that can determine this at run time and solve (so that when it's running on some other terminal, with some other charset, with someother file system charset it will still work).
    Any ideas for doing this from withing the VM?
    p.s. thanks for the fast reply.

  • A column in a table has physical file path (I want to get file size of those docs from the OS)

    Experts!!
    I have a table that holds the physical file path of files in one of its columns. It does not give a link, just the physical file path.
    For example,---- C:\bu\test.pdf   and let us say the file size is kb according to the OS.
    Is there any way I can obtain the file size of the files from the physical path?
    for example, the file size of the test.pdf file in the example here using t-SQL?
    Much Appreciation
    ebro

    Hey there... thanks for the response......I found the following as a solution for my problem. But my problem is the SP created using the method needs a directory as a parameter. How can I pass the directory from a table that holds my directory?
    EXEC  [dbo].[GetListOfFileWithSize](@Dir)
    How do I pass the directory from my table?
    http://stackoverflow.com/questions/7952406/get-each-file-size-inside-a-folder-using-sql/7958070#7958070
    ebro

  • Strange File Size Problem (FLA)

    Hi
    We just encountered quite a problem here and i wonder how to solve it. Our FLAs are getting so huge that they are mostly "un-workable".
    Basicly, what we do is create a character animation, let's say a walk cycle. For that part we use stardard animation. Multiple layers for everybody part, and tweening them. Then, for some reason, we need to break it appart into frames with shapes. so we break our whole animation into frames until everyframe only has a shape on it.
    But this takes some HUGE space. I wonder if there's some hidden meta-data on the shape that remember it once was into an animation, or a clip or anything else alike.
    Every Shape takes about 160k. a simple square takes 160k. If i take that shape. paste it into a new fla, saves it, it'l take 160k on my disk. If i create a new fla, create an identical shape, it'l take about 16k. Ok this might seem like no big deal, but our FLA is now over 170 megs instead of something around 16. And it creates quite a few problem from there working with those files, sharing them, and exporting the units inside of it.
    Anybody encountered this issue and knows how to solve this ?

    anyone ?
    I attached 2 files that are very similar to me, the big one is 157k after a save and compact, and the SmallOne where i tried to reproduce the shape, is 21k after a save and compact. Where does those 136k comes from, it's not file based cause if i put 2 shapes in there, the file size is getting multiplied =/
    edit : Oh well, looks like i can't post fla attachement.. weird

  • PDF File Size Problem

    Hi,
    I am using Adobe Acrobat Elements 7.0 in my computer to convert files like .txt and .doc to .pdf files. But currently I'm facing a problem with the converted .pdf file size. For example, my .doc file is 5MB and after I convert to a .pdf file, it becomes 10MB. The file size basically multiplies itself by 2.
    I've tried converting .txt and .doc files and it gives me the same problem. I've tried reinstalling, tried all kinds of settings, and recreating user profile but it doesn't help. Can anyone help me? Thank you very much.

    Sorry. The problem is caused when I want to password protect a .pdf using elements. So I used Adobe Reader to open the .pdf file then I'll print using Adobe Printer so that I can password protect it and output file size is actually 10 times the normal .pdf file.
    Please help!!

  • Get file size value for export to .txt

    I have created a script to export metadata using the XMP Script Library.  I am able to get all the properties I need except one: image file size (not dimensions, but the size of the file itself in MB).  File size is not included in any XMP namespaces and it isn't in any TIFF tags as far as I can tell.
    Getting the file name is very straightforward: exportFile.write (thumb.name), but I can't find any method to get the file size.
    Any ideas would be a big help.
    Thanks in advance,
    Greg Reser

    var sels = app.document.selections;
    alert(sels[0].spec.length);
    This will get you the file size in bytes, then you can divide to get Mbytes.

  • PDF to TIFF conversion Tiff File Size problem after conversion

    Hi,
    I am able to convert the PDF file into multi page TIFF file using the below method. But i am getting a size of 1.3 mb for each page of TIFF file (noofpagesX 1.3 mb). it's huge size right? So Could any one please help me out how to decrease the size of the TIFF file? It's an urgent for me. help me out.....
    public static byte[] PDF2TIFF(byte[] bai, String imageType) {
    byte[] out = null;
    try {
    PdfDecoder decoder = new PdfDecoder();
    decoder.openPdfArray(bai);
    decoder.setSize(100, 100);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    BufferedImage image[] = new BufferedImage[decoder.getPageCount()];
    TIFFEncodeParam param = new TIFFEncodeParam();
    param.setCompression(TIFFEncodeParam.COMPRESSION_PACKBITS);
    param.setLittleEndian(true);
    param.setWriteTiled(false);
    if (decoder.isFileViewable()) {
    for (int i = 0; i < decoder.getPageCount(); i++) {
    int pageNumber = i + 1;
    BufferedImage imageTemp = decoder.getPageAsImage(pageNumber);
    System.out.println("Page Number."+pageNumber);
    image[i] = imageTemp;
    ImageEncoder encoder = com.sun.media.jai.codec.ImageCodec.createImageEncoder("tiff", baos, param);
    Vector vector = new Vector();
    for (int i = 1; i < image.length; i++) {
    vector.add(image);
    param.setExtraImages(vector.iterator());
    encoder.encode(image[0]);
    baos.flush();
    baos.close();
    decoder.closePdfFile();
    out = baos.toByteArray();
    catch (Exception e)
    e.printStackTrace();
    return out;
    Thanks
    Sha                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    For the Batch Sequence that "asks" --
    Something to try.
    Open the Batch Sequence dialog.
    Select the appropriate Batch Sequence.
    Click the Edit button.
    In the Edit Batch Sequence - <name of sequence> dialog, use item number 3's drop-down menu.
    From the menu, select 'Same folder as originals'.
    "OK" out of the dialog.
    Give the Batch Sequence a test run.
    Output ought to be to the same folder as that of the selected & processed files.
    Be well...

  • File size problem when performing XML Transformation into Excel

    Hi All,
    We are performing XML Transformation in ABAP which can open in Excel and saving to common share. But the file size of excel is around 50MB. After opening the excel and save with diffrent name the file is getting compressed and its below 1MB. So what kind of settings does we need to make to the transformation code which will create the excel files with less memory/size??
    <?sap.transform simple?>
    <tt:transform xmlns:tt="http://www.sap.com/transformation-templates">
    <tt:root name="AAAAAAA"/>
    <tt:root name="BBBBBBBB"/>
    <tt:root name="CCCCCCCC"/>
    <tt:template>
    <?mso-application progid="Excel.Sheet"?>
    <Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
    xmlns:o="urn:schemas-microsoft-com:office:office"
    xmlns:x="urn:schemas-microsoft-com:office:excel"
    xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882"
    xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
    xmlns:html="http://www.w3.org/TR/REC-html40">
       <ProtectObjects>True</ProtectObjects>
       <ProtectScenarios>True</ProtectScenarios>
      </WorksheetOptions>
    </Worksheet>
    </Workbook>
    </tt:template>
    </tt:transform>
    <DocumentProperties xmlns="urn:schemas-microsoft-com:office:office">
    </DocumentProperties>
    <CustomDocumentProperties xmlns="urn:schemas-microsoft-com:office:office">
      <ContentTypeId dt:dt="string">0x01010049B4763FE606154C9C9BC639FE7EE179</ContentTypeId>
    </CustomDocumentProperties>
    <OfficeDocumentSettings xmlns="urn:schemas-microsoft-com:office:office">
      <Colors>
       <Color>
        <Index>0</Index>
        <RGB>#FF0000</RGB>
       </Color>
       <Color>
        <Index>1</Index>
        <RGB>#FFE4B5</RGB>
       </Color>
       <Color>
        <Index>2</Index>
        <RGB>#FFF8DC</RGB>
       </Color>
       <Color>
        <Index>3</Index>
        <RGB>#000000</RGB>
       </Color>
      </Colors>
    </OfficeDocumentSettings>
    <ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel">
      <WindowHeight>7305</WindowHeight>
      <WindowWidth>11340</WindowWidth>
      <WindowTopX>0</WindowTopX>
      <WindowTopY>0</WindowTopY>
      <TabRatio>334</TabRatio>
      <ProtectStructure>True</ProtectStructure>
      <ProtectWindows>False</ProtectWindows>
    </ExcelWorkbook>
    </DocumentProperties>
    <CustomDocumentProperties xmlns="urn:schemas-microsoft-com:office:office">
      <ContentTypeId dt:dt="string">0x01010049B4763FE606154C9C9BC639FE7EE179</ContentTypeId>
    </CustomDocumentProperties>
    <OfficeDocumentSettings xmlns="urn:schemas-microsoft-com:office:office">

    Hi Raghu,
    have a look at the XLSX file generated by Excel, you'll see that it's simply a zipped file. So you can't do it with a transformation, but you need CL_ABAP_ZIP class. I advise you to look at the abap2xslx project ABAP code (currently 3.0) to see how it works.
    Best regards,
    Sandra

  • File size problem between Acrobat 8 and 9

    When I print to a PDF from Acrobat 8 I get a file size that is slightly larger than the original PDF file size.  Example a 1.6 mb file becomes a 1.7mb file.  When I print the same file in Acrobat 9 with the same settings (to my Knowledge) (setting = High Quality Print) I get a file that 36.1mb.
    The reason we would print the file in the fist place is that we need to create a PDF that is ether slightly larger or slightly smaller (say 98%) of the original size.  Can anyone help us figure out why our upgraded version 9 would do this?  We also use 7 and between 7 and 8 there are no defenses but 9 makes the file ~21X the original file size.  Please see that attached JPEG for a screen shot of the file sizes.
    Thank you, -Dan

    Thank you for the quick response.  We are able to get some results through the Optimizer however they are not the same.  Also we would like to keep from adding an extra step into the process.  Especially a step that adds a lot of time to the process as the Optimizer does.  In versions 7 and 8 we did not have run the Optimizer (we also did not have to do this in version 5 back in the day).  Why would 9 have to add this step?  I am really looking for a way to keep the same workflow steps.  -Dan

  • IPhone 5 backup file size problem

    Hi,
    On Monday I have upgraded from iPhone 4 to iPhone 5. I have setup the iPhone 5 as old (not new device) and restored all settings and data
    via iCloud from my iPhone4 backup. Everything works just fine , except I have a problem with the size of the new iPhone 5's backup file.
    iPhone 4's backup files , both on iCloud and my laptop, have the size of 236 MB. iPhone 5's backup file size is only 58 MB.
    The backup file size is the same when using OTA iCloud backup or iTunes backup.
    What am I missing ?
    iPhone 5, iOS 6.0.2, iTunes 11.0.1.12, Windows 7 64bit.
    Regards,
    Alex

    Your question is interesting.  I don't really know the answer, but if that happened to me, I'd be delighted!
    After all, you're saying everything is working just fine, and yet your new backup is 25% the size of your old one.  I would view that as the backup is being done a whole lot more efficiently, with old junk having been discarded.
    I would be really upset and concerned if the backup size went the other way -- if the new backup was 4 times the size of the old one.
    Basically, you will find efficiencies in storage used on your iOS device if you restore it.  I suspect you're seeing similar efficiencies here.  Given everything is working fine, it sounds like cause for celebration.
    Enjoy your new iPhone.

  • File receiver - Get file size

    Hi all,
    In my scenario, the message mapping is such that the target message may or may not have child nodes created depending on certain conditions. I am using file receiver channel to write this target message as xml file on another server.
    The issue I am facing is - suppose child nodes are not created, the target message has only root node, and nothing else. i.e. it is empty.
    But still the file gets written on destination, because file adapter doesn't seem to have intelligence to look into the payload. So I have to manually delete such 'almost-empty' files.
    Although PI 7.0 has feature of ignoring empty files, the file I am talking of is really not of 0 kb size, as it contains namespace and root node tag. It has very small size of 1 kb, this is fixed and thus the file is easily distinguished from other larger files which contain child nodes. File size is a parameter that can be certainly used as a key here, but don't know how.
    Does anyone have any idea on -
    1) How to check file size before file receiver adapter writes it,
    2) How to prevent such file from getting written, or
    3) run a script which can detect the file size and delete them periodically / or every time file receiver writes files ?
    Regards,
    - Shankar.

    Hi,
    We have an option of empty file handling in receiver file adapter..
    <i>      Select the Handling of Empty Messages:       Write Empty File
    An empty file (length 0 bytes) is put in the target directory.
           Ignore No file is put in the target directory.</i>
    But your case namespace and root node only are available you said.
    In this type of situations ..
    We can handle in the following way..
    If target side root node having the recordset node
    root
      recordset 0..unbound
         child1 0.1
         child2   0.1
    Then create a UDF
    map from left side one node -
    exists --- UDF ---to right side root node
    In UDF
    //handle business logic and
    ....ResultList.SUPPRESS.
    if your target side does not have any recordset type of structure then..
    In messages tab change the occurrences of msg to 0..unbound and use the above UDF.
    Regards
    Chilla..

  • File Size Problem

    I got a picture of 4kb, and used photoshop(cs4) to paint white all,so it changed to white rectangle, then saved it.
    that's for web site logos, so it must keep the picture size same as original (ex, 70px * 50px).
    The problem I have was, the saved picture(with png, jpeg, gif, or any format)  has a size of over 40k bite.
    This is rediculous, so, please tell me how to make the file size at most the original size, i.e. 4kb by using Photoshop, if it is possible.
    Thanks.

    toshuu8 wrote:
    I didn't see how to disable the writing of Metadata and embedded color profile
    You're welcome. 
    -Noel

  • FCP - Massive file size problem.

    So I've been exporting out a 21min sequence out of fcp 7.  In past edits and on the same project file, the export has been fine, rendering out at a healthy 6gb.   But recently the final file size has become 29gb.  This is obviously not right.  My question is, what is going on and how can I fix it? 
    The only thing that has changed is I've done a color grade (from Color).  So some of the files are different,  but the new color graded clips aren't any bigger than the origianl ones, so I don't think thats the problem.
    Another random thing that happend is:  When exporting I give the file a name, e.g. Helloworld   And I select show file extension.  The weird thing is when it's completed its export, the file name then becomes Hellowordmov.mov   I have not idea where that extra mov is coming from, (and it doesnt appear when I select show file extension).  What is going on here?
    Below are my sequence settings.  I chose File -  Export -  Quicktime Movie...  And keep it on Current Settings.
    Any help is much appreciated.

    The Digital Rebellion Video Space Calculator shows 28.23 GB.
    http://www.digitalrebellion.com/webapps/video_calc.html?format=prores_422_hq_108 0&frame_rate=f25&length=21&length_type=minutes

  • Using LR and DxO in work flow.. file size problems

    Hi,
    Does anyone have experience with using both DxO and LR in their work flow that can help me with the following problem?
    DxO takes my NEF and creates a DNG optically corrected. Great. Now I should just import these DNG files into LR and be on my way.. except that it seems to use Linear DNG rather then mosaiced and the file sizes are through the roof. My 10mb NEF file is converted into a 30mb DNG. Trying to reconvert using LR has no effect. If I start working with images in this size I will immediately see all my storage space cut by a third from the point of view of the number of images stored.
    Has anyone found a way to work around this problem? I tried to use the adobe DNG converter to reconvert the images but it can go from mosaic to linear but not linear to mosaic. Turning on compression has no effect implying it is already a compressed DNG. Trying to zip the files also fails to have an effect.
    I am really bummed out.. and wish I had paid more attention to file sizes during my trial.
    Right now I am leaning toward only using DxO for a few special images and doing the rest entirely in LR.. but that really defeats the purpose of what I thought would be a great one two punch.
    Thanks,
    Chris

    David,
    The output preset you're using must have TIF enabled. Either edit it to remove the TIF option or create a new JPG-only one if you want to keep the option of exporting to both in the future.
    I can't be more precise as I'm currently away from home and the DxO installation on my laptop has decided to deactivate and revert to time-expired demo mode, meaning I can't actually open the app!
    [Edit]
    Okay, sorted now.... In the DxO Optics Pro "Process" module, under the "Options" section you'll see "Output Formats". There should be one called "Default Output" which outputs to JPG. Ensure that the checkbox next to it is checked and that any others are disabled (unchecked). Your images will now only be exported after processing as JPGs. If you click the "X" next to an output preset you can delete it if no longer required.
    Alan

  • Export file size problem

    I have a .png image which is currently, and needs to remain on a transparent background.
    The canvas size is 1947 x 926 pixels and its resolution is 300 pixels/inch.
    The math will tell you that the physical size of this image is roughly 6.5 inches x 3.1 inches (which is the final size I need the image to be once it gets inserted into a Microsoft Word document).
    The file size is 1.80 MB.
    Is there a way to reduce the file size, without sacrificing image quality once the final Word document gets printed? 
    What format should I export the image as, keeping in mind that the background must remain transparent?
    The .png image currently has around 50 layers.  Do I gain anything by flattening the layers or something similar?
    Thank you for any advice you can offer.
    Brian

    Go to File > Image Preview, and choose the PNG32 format. This is a good all-around format that supports transparency and non-lossy compression. In the upper-left corner of the preview window, you'll see the output size; it should be a lot less than your current file size. From here, you can click "OK" to save the settings or you can Export.
    For an even smaller file size, you could try PNG8 with Alpha Transparency, but this format allows only 256 colors (like the GIF format), which makes it a good choice only for flat graphics (i.e., text and vector-based artwork), not for bitmaps or gradients.
    As far your original Fireworks PNG file, you could likely reduce its size by flattening layers—particularly bitmaps. But then you'll sacrifice editability. And it won't impact the output size when exporting the file. So I'd probably leave it as is.

Maybe you are looking for

  • Issue with last-page-first Body (header of second page repeating)

    Hi, I am generating some invoice document and there is tax section at the end of document.Invoice can be one page document or it can be multiple pages document.I also have separate header and footer for first page and then for subsequence pages. Assu

  • How Can I Have Totals On Only One Record?

    Hi.  I don't have a clue where to start with my query.  I thought I had it, but turns one I'm missing something. I have a master table with three detail tables. In the detail tables, it is possible to have multiple records.  In one of the detail tabl

  • How can I allow standard users to update creative cloud without admin rights.

    I have over 300 users in a domain environment  and I cannot allow them to have admin rights on the machines.Is there a Registry hack or key that we can adjust to allow CC to update without these rights?

  • Uploading Business Partner Opening Balances

    Hi     All            I want upload business partner opening balance by DTW or Import data is it possiable???? Thanks & Regards Amit

  • ODI integtation with e-Business Suite Release 12

    Hello, Has anyone successfully used ODI to integrate date into e-Business Suite Release 12? I notice that the only e-Business Suite IKM is specific to Open Interface tables. Is this a problem in R12 where the documented interfaces in the Integration