How to get the size of file
Hi
I want to know the size of the file from Java. ie If i have 10 lines in that file each of 15 characters
then 10 *2*10=200Bytes is the size. How will i get this?
More over, if i am reading the 4 the line, how will get the info that I have read 3 lines =3*2*10= 60 bytes so far?
Regards
Sriram
This is from the JavaDocs on java.io.File
length
public long length()
Returns the length of the file denoted by this abstract pathname. The return value is unspecified if this pathname denotes a directory.
Returns:
The length, in bytes, of the file denoted by this abstract pathname, or 0L if the file does not exist
Any of the read methods (except readLine()) on the many stream objects return the number of bytes read, simply accumulate these returns to know how many bytes have been read.
Dave
Similar Messages
-
How to get the size of a file DONE
How can I get the size a file? I want to do the following....
File clobDataFile = new File("clob.dat");
PrintWriter clobpw = new PrintWriter(new BufferedWriter(new FileWriter(clobDataFile)));
int offset = //get the number of chars in the fileOk I am a tard... figured it out...
File clobDataFile = new File("clob.dat");
PrintWriter clobpw = new PrintWriter(new BufferedWriter(new FileWriter(clobDataFile)));
int offset =colbDataFile.length();read API http://java.sun.com/j2se/1.5.0/docs/api/java/io/File.html#length()
next time you have a similar question please refer this document -
How to get the size of driver[C: or D:]
Hi Friends,
I have a query regarding to java..
I want to get the name of all the drives that r connected to the System including network drives...
and how to get the size of any system drive[For example C: or D: Drive].
I want the output to be displayed like in the following format
Device type size free Usage_Space
for ex.
C: NTFS 37.5Gb 30.5gb 7gb
Output like as linux command df -h
Edited by: KituPrash on Mar 4, 2009 3:29 AMDoes this help for starters?
File[] roots= File.listRoots();
for (int i= 0; i< roots.length; i++)
System.out.println(roots[i]+": "+roots.getTotalSpace());kind regards,
Jos -
How to get the most current file based on date and time stamp using SSIS?
Hello,
Let us assume that files get copied in a specific directory. We need to pick up a file and load data. Can you guys let me know how to get the most current file based on date and time stamp using SSIS?
Thanks
thx regards dinesh vvhi simon
i excuted this script it is giving error..
Microsoft SQL Server Integration Services Script Task
Write scripts using Microsoft Visual C# 2008.
The ScriptMain is the entry point class of the script.
using System;
using System.Data;
using Microsoft.SqlServer.Dts.Runtime;
using System.Windows.Forms;
namespace ST_9a6d985a04b249c2addd766b58fee890.csproj
[System.AddIn.AddIn("ScriptMain", Version = "1.0", Publisher = "", Description = "")]
public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
#region VSTA generated code
enum ScriptResults
Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success,
Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
#endregion
The execution engine calls this method when the task executes.
To access the object model, use the Dts property. Connections, variables, events,
and logging features are available as members of the Dts property as shown in the following examples.
To reference a variable, call Dts.Variables["MyCaseSensitiveVariableName"].Value;
To post a log entry, call Dts.Log("This is my log text", 999, null);
To fire an event, call Dts.Events.FireInformation(99, "test", "hit the help message", "", 0, true);
To use the connections collection use something like the following:
ConnectionManager cm = Dts.Connections.Add("OLEDB");
cm.ConnectionString = "Data Source=localhost;Initial Catalog=AdventureWorks;Provider=SQLNCLI10;Integrated Security=SSPI;Auto Translate=False;";
Before returning from this method, set the value of Dts.TaskResult to indicate success or failure.
To open Help, press F1.
public void Main()
string file = Dts.Variables["User::FolderName"].Value.ToString();
string[] files = System.IO.Directory.GetFiles(Dts.Variables["User::FolderName"].Value.ToString());
System.IO.FileInfo finf;
DateTime currentDate = new DateTime();
string lastFile = string.Empty;
foreach (string f in files)
finf = new System.IO.FileInfo(f);
if (finf.CreationTime >= currentDate)
currentDate = finf.CreationTime;
lastFile = f;
Dts.Variables["User::LastFile"].Value = lastFile;
Dts.TaskResult = (int)ScriptResults.Success;
thx regards dinesh vv -
How to get the number of files currently open?
hi,
does any one know how to get the number of files currently open in windows OS?
e.g. lets say .txt files...
any comment will be really appreciated.
thanksAssuming that you don't want to actually do this from within Java code (which would obviously require native code), here's a utility that will give you a list of which file handles are opened by which processes (on Windows):
http://www.sysinternals.com/ntw2k/freeware/handle.shtml
- K -
How to get the current executing file/itself absolute directory?
hellooo,
gentlemen/lady, how to get the current executing file/itself absolute directory?
thanks
Hello,
you can get the real path information of the JSP through the servlet context:
http://java.sun.com/products/servlet/2.2/javadoc/index.html
javax.servlet
Interface ServletContext
Method getRealPath
Christian Plenagl
Developer Relations Engineer
BEA Support
[email protected] (alex mok) wrote:
>hellooo,
>
>gentlemen/lady, how to get the current executing file/itself absolute
>directory?
>
>thanks
-
How to get the size of physical memory by using system call ?
how to get the size of physical memory by using system call ?What system call can be used for me to get the size of physical memor? thanks.
%vmstat 3
procs memory page disk faults cpu
r b w swap free re mf pi po fr de sr s0 -- -- -- in sy cs us sy id
0 0 0 3025816 994456 4 19 6 0 0 0 0 8 0 0 0 459 253 139 1 1 99
0 0 0 2864688 777408 0 2 0 0 0 0 0 3 0 0 0 428 134 175 0 1 99
0 0 0 2864688 777408 0 0 0 0 0 0 0 7 0 0 0 448 112 166 0 0 100
one interesting observation about vmstat I found out is (mostly on Solaris)
the first line of information always off chart, so I usually do a few interval to get constant result.
if you use linux
just
cat /proc/meminfo -
How to get the size of partition?
The following SQL will get the rows of the fact table & aggregation. But how to get the size (MB) of the partition. select * from $system.discover_partition_stat That should be doable, because in BIDS, we can see the size of a partition, but from which
view we can do that?This is the best bet you have SELECT * FROM SystemRestrictSchema($system.discover_partition_stat ,DATABASE_NAME = 'Adventure Works DW' ,CUBE_NAME = 'Adventure Works' ,MEASURE_GROUP_NAME = 'Internet Sales' ,PARTITION_NAME = 'Internet_Sales_2003') Refer
this article: http://geekswithblogs.net/darrengosbell/archive/2008/12/02/ssas-are-my-aggregations-processed.aspxvinu -
How to get the size of the webpage?
I am designing a program to
analyse the webpage content.
wondering how to get the size of
the webpage including its image's
size and etc. Thanks in advance.As i know , the getContentLength just return
then number of characters of its HTML code.
By knowing the length of the HTML code, is
not possible for me to calculate its download
time... i wonder is there any way to get the
total size of the page including its image size,
applet size, and etc... Thanks : ) -
How to get the size of a hard disk?
Hi,
As above, how to get the size of a hard disk by using Java.
Thanks you!
AlexI would be interested in the answer of this question, too.
In core Java there is no way to find it out in a platform independent manner because of the hardware abstraction of the VM. So my only idea is to write a native library for doing this and colling it via JNI -
How to get the size of the table
Hi All,
How to get the size of the table in Oracle 10g?
Is there any script which needs to be run?
Regards,
ApoorvHi All,
Sorry but somehow the table user_segments is not populated in my case. But we have another table SYS.ALL_TABLES whose structure is given below. Would I be able to calculate the table size based on the columns given below:
ColumnName Data Type
OWNER VARCHAR2 (30 Byte)
TABLE_NAME VARCHAR2 (30 Byte)
TABLESPACE_NAME VARCHAR2 (30 Byte)
CLUSTER_NAME VARCHAR2 (30 Byte)
IOT_NAME VARCHAR2 (30 Byte)
STATUS VARCHAR2 (8 Byte)
PCT_FREE NUMBER
PCT_USED NUMBER
INI_TRANS NUMBER
MAX_TRANS NUMBER
INITIAL_EXTENT NUMBER
NEXT_EXTENT NUMBER
MIN_EXTENTS NUMBER
MAX_EXTENTS NUMBER
PCT_INCREASE NUMBER
FREELISTS NUMBER
FREELIST_GROUPS NUMBER
LOGGING VARCHAR2 (3 Byte)
BACKED_UP VARCHAR2 (1 Byte)
NUM_ROWS NUMBER
BLOCKS NUMBER
EMPTY_BLOCKS NUMBER
AVG_SPACE NUMBER
CHAIN_CNT NUMBER
AVG_ROW_LEN NUMBER
AVG_SPACE_FREELIST_BLOCKS NUMBER
NUM_FREELIST_BLOCKS NUMBER
DEGREE VARCHAR2 (10 Byte)
INSTANCES VARCHAR2 (10 Byte)
CACHE VARCHAR2 (5 Byte)
TABLE_LOCK VARCHAR2 (8 Byte)
SAMPLE_SIZE NUMBER
LAST_ANALYZED DATE
PARTITIONED VARCHAR2 (3 Byte)
IOT_TYPE VARCHAR2 (12 Byte)
TEMPORARY VARCHAR2 (1 Byte)
SECONDARY VARCHAR2 (1 Byte)
NESTED VARCHAR2 (3 Byte)
BUFFER_POOL VARCHAR2 (7 Byte)
ROW_MOVEMENT VARCHAR2 (8 Byte)
GLOBAL_STATS VARCHAR2 (3 Byte)
USER_STATS VARCHAR2 (3 Byte)
DURATION VARCHAR2 (15 Byte)
SKIP_CORRUPT VARCHAR2 (8 Byte)
MONITORING VARCHAR2 (3 Byte)
CLUSTER_OWNER VARCHAR2 (30 Byte)
DEPENDENCIES VARCHAR2 (8 Byte)
COMPRESSION VARCHAR2 (8 Byte)
DROPPED VARCHAR2 (3 Byte) -
Hi all,
Can any one tell how to get the number of files(.EPS) count inside a folder when the folder path is specified in VC++ 6.0?
Thanks in Advance.
Regards
myriazI'm a little confused by the question, but it sounds like you're asking how to count the number of files with a particular extension in a given directory? That's not really an AI SDK question, but it's a fairly easy one to find if you google it. If you're trying to use Illustrator to do it, AI doesn't have a general purpose file API. It has a few functions to do some things that Illustrator needs, but I don't think enumerating directories is one of them.
-
How to reduce the size of file after delete some datas?
The size of the database file isn't smaller than ago after delete some data from database.
How to reduce the size of file after delete some datas?Hi,
What BDB release are you using? If it's one of the latest releases, then what you are looking for is the DB->compact() method:
http://download.oracle.com/docs/cd/E17076_01/html/api_reference/C/dbcompact.html
The DB->compact() method compacts Btree, Hash, and Recno access method databases, and optionally returns unused Btree, Hash or Recno database pages to the underlying filesystem. Please let me know if it helps.
Bogdan Coman -
How to get the size of the file
Hi All,
I want to get the size of the file in terms of bytes. I used the following code it returns the value in long how can get it in bytes
import java.io.File;
public class ServerBackupCheck {
public static void main(String args[]){
File f = new File("C:/Program Files/Apache Software Foundation/Tomcat 5.5");
System.out.println(f.isDirectory());
System.out.println(f.getTotalSpace());
output:
true
20964163584
regards,
Maheshwaran Devarajif it is a folder you can use this recursive algorithm
public static long recurse(File f) throws IOException
long bytes = 0;
File files[] = f.listFiles();
for(int i =0 ;i<files.length;i++)
File file = files ;
if(file.isFile())
FileInputStream fis = new FileInputStream(file);
byte[] by = new byte[fis.available()];
fis.read(by);
bytes = bytes + by.length;
if(file.isDirectory())
bytes = bytes + recurse(file);
return bytes;
System.out.println(recurse(f)); gives you the total bytes....
Ayberk Cansever .. -
How to get the size of the blob file uploaded ?
Hi ,
Is there anyway to get the size of the file i have uploaded to a blob type attribute ?
What i can see is that when we upload a file in contributor UI ,once the file is uploaded successfully and if we hover on it , it will show the filename , type and size of the uploaded file .
From where can we get that details so that we can reuse these details in our code ?
Thanks and Regards,
PraveenA filter is a sensible solution, or you can get it in a roundabout way like this for example if you have the blobid (this is paraphrased from OpenMarket/Gator/AttributeTypes/IMAGEPICKERShowImages.jsp):
<ics:sql sql='<%="select urldata,filevalue from MungoBlobs where id=" + ics.GetVar("blobid")%>' listname="blobdata" table="MungoBlobs" />
<ics:listget listname="blobdata" fieldname="urldata" output="urldata" />
<ics:setvar name="blobpath" value='<%=ics.GetProperty("cc.urlattrpath", "gator.ini", true) + ics.GetVar("urldata")%>' />
<%
File blobFile = new File(ics.GetVar("blobpath"));
long length = blobFile.length();
%>
Phil
Message was edited by: pgleghorn
Maybe you are looking for
-
How to show a photo in pages by VC?
How to show a photo in the table or the detail in the pages generated for the Composer Appearance? Example: The user makes a search, receives as resulted a book list, he would like to show in this list an icon with the cover of each book and when cli
-
Screen goes wacky after possible overheating
I recently updated my phone to iOS 8.2 (I didn't skip any versions, I was just lagging ~2 months behind on downloading 8.2). Soon after (though I'm not sure it's related) -- within a week -- my phone got really...wonky. I have a YouTube/video link to
-
Can I connect a real instrument?
I use garage band 3.0.4 and I want to know if I can connect my bass directly to the computer, and if it is possible, how does it work? do I have to change any configuration? thanks!
-
Hey; My friend was showing me "Media Monkey" on his (Shudder) widows machine... and it had an awesome feature called "Party Mode" ... When activated the user could not switch away from "Media Monkey" (basically locked the computer - Password required
-
Update Custom Field in Task Level Project Server using JSOM (PS.js)
Does anyone have javascript which updates the task level custom field? I just have the code with C#. I am trying to convert this code to javascript (below). But the javascript code had failed in update process. When I see queue jobs, JobState: Report