Which is theb best way to read a file of 5-10 mb
Hi,
I need to read a flatfile of 5-10 mb and simultaneously insert into database .
Reading through FileInputStream or FileReader?
Which is the best approach to do this keeping in considerataion performance and memory management.
Please help .Its is an urgent task to be done.
Thanks,
kazim
Message was edited by:
kazimh
I always use the following example.. mayb that would help you as well
File fid = new File(fileName);
if (fid.exists())
fr = new FileReader(fid);
br = new BufferedReader(fr);
while((txtstr= br.readLine()) != null)
}
Similar Messages
-
The best way to read properties file
Hi folks,
The best way to read properties file i.e.. using ResourceBundle or FileInputStream . if so how to do it , my properties file is n WEB-INF/classes/myprop.properties.It's urgent.
Thanks & Regards,
Rajeshwar.WEB-INF/classes should be in your classpath. The web container takes care of that.
All you have to do is call ResourceBundle.getBundle("myprop").
It'll append the .properties for you.
http://java.sun.com/j2se/1.5.0/docs/api/java/util/ResourceBundle.html#getBundle(java.lang.String) -
What is the best way to read a file line by line?
Hello, everyone!
I want to read a file line by line, i.e. each time, a line of a text file is read and stored as a String object and the String object will be manipulated (parsed) later.
I have found that FileInputStream does not have a function which is responsible for reading a line each time from a text file. Anyone have good suggestions?
Best regards,
GeorgeI always use the following example.. mayb that would help you as well
File fid = new File(fileName);
if (fid.exists())
fr = new FileReader(fid);
br = new BufferedReader(fr);
while((txtstr= br.readLine()) != null)
} -
Best way to read text files at multiple production sites
Need to write a solution to read txt files that contain binary data on multiple SQL Servers. I have no control over the SQL servers, they are not mine. Thinking of BULK INSERT or bcp. But must something on the server be turned on for it to work? What are
some other production solutions for reading files and loading the data into a SQL table?Hello,
I think the best way is create a SSIS package to import data into SQL Server tables. Here are some articles for your reference:
http://codejotter.wordpress.com/2010/04/06/importing-multiple-text-files-using-ssis/
http://technet.microsoft.com/en-us/sqlserver/dd941934.aspx
Regards,
Elvis Long
TechNet Community Support -
Hi All,
I'm curious to know what is the best (fast) way to read a binary file. In particular, I'm thinking if using a BufferedInputStream I can obtain better results.
In my opinion the FileInputStream class should be already optimized to read bytes from the underlying OS so that using BufferedInputStream I should not have benefits.
If this is true, FileInputStream.read() should have the same performances of FileInputStream.read(byte[]).
Is it correct ?
stewhat I expect for 1 is the FileOutputStream collects all bytes in a buffer calling OS when the buffer is full or if flush() is called. I don't think all the difference (30s vs 100ms) is since method invocations overhead.That's not what it does. It has no built in buffer, as far as I am aware.
I created this test to test the cost of method overhead. This is using read(), but could be changed to use write. It shows definite performance effects to doing single reads repeatedly on a 5 meg byte array input stream (as opposed to one read) but nothing that's going to compare to reading latency from an actual file
public static void readTest() {
byte[] vals = new byte[5000000];
for (int i = 0; i < vals.length; i++) {
vals[i] = (byte)(i % 256);
ByteArrayInputStream in = new ByteArrayInputStream(vals);
long time1 = System.currentTimeMillis();
for (int i = 0; i < vals.length; i++) {
in.read();
long time2 = System.currentTimeMillis();
in = new ByteArrayInputStream(vals);
try {
int got = in.read(new byte[5000000]);
System.out.println("got: " + got);
catch (IOException iox) {
iox.printStackTrace();
long time3 = System.currentTimeMillis();
System.out.println("read each: " + (time2 - time1));
System.out.println("read batch: " + (time3 - time2));
} -
Which is the best way to transfer the file through the LAN
I need to transfer files of Size in MB from one PC to another. I have done it by File Copy function with the file path "\\Receiver\C:\File.txt". but it takes 1 Sec approximately for the 10KB of file size. I also need to monitor the file transfer progress. Please suggest the best way to transfer file faster.
Thanks for the Valuable feedback.
Actually the File format I have to tranfer is *.vlf (these file are taken for printing) which is of few MB of size I didnt try to transfer this format file. For the testing purpose I have tried with text files.
Please tell me how to address the destination path (administrative
share of C$ ). I dont know about UNC path.
In my Code:
After transferring files to the destination path (path - which is always accessed by the Printer). I have to send command to the PLC that triggers the printer then printer take these files. After these cycle complete, I replace the files with the File Copy Function then again printer is triggered by the PLC - command. If the PLC command sent after the file transfer sequence, the PLC will immediately triggers the printer to print the file. I have nearly 500ms of time to transfer two of these files.
All i want to know is File Copy function completes its job after transfer or it just commands to do so. I should not give the command to plc while file tranfer in progress.
Also please tell me is it possible to monitor the file being transfered ?
Thanks & Regards
Sridhar -
Best way to read in File of characters...
I have a file whose size is roughly 16k-20k.
I need to read in the file and perform some logic based on each character of the file.
Is wrapping a FileReader within a BufferedReader the most efficient way to do this? Or is there some nio package or custom buffer stuff I can do to speed it up?
thanksI gues if you have to check the charactars multiple times putting the file in a string or
stringbuffer would be faster. If you read it only once you might use a bufferedreader.
I'm not verry experienced but think that the charset is importaint, here is some code
on how I red Japanese text. I changed the getBytes to create the string in ASCII.
try{
File f = new File("somefile");
FileInputStream fi = new FileInputStream(f);
byte[] buf = new byte[1024];
int len;
int i = 0;
ByteArrayOutputStream bos = new ByteArrayOutputStream();
while ((len = fi.read(buf)) > 0) {
bos.write(buf, 0, len);
byte[] data = bos.toByteArray();
// String dataString = new String(data,"ASCII");
fi.close();
}catch(Exception e){
e.printStackTrace();
} -
What is the best way to read and manipulate large data in excel files and show them in Sharepoint
Hi ,
I have a large excel file that has 700,000 records in it. The excel file has a few columns that change every day.
What is the best way to read the data form the excel file in fastest and most efficient way.
2 nd Problem,
I have one excel file that has many rows each row contain some data that has certain keywords.
What I want is to segregate the data of rows into respective sheets(tabs ) in the workbook.
for example in rows have following data
1. Alfa
2beta
3 gama
4beta
5gama
6gama
7alfa
in excel
I want there to be 3 tabs now with each of the key words alfa beta and gamma.Hi,
I don't really see any better options for SharePoint. SharePoint use other production called 'Office Web App' to allow users to view/edit Microsoft Office documents (word, excel etc.). But the web version of excel doesn't support that much records as well
as there's size limitations (probably the default max size is 10MB).
Regarding second problem, I think you need some custom solutions (like a SharePoint timer job/webpart ) to read and present data.
However, if you can reduce the excel file records to something near 16k (which is supported rows in web version of excel) then you can use SharePoint Excel service to refresh data automatically in the excel file in SharePoint from some external sources.
Thanks,
Sohel Rana
http://ranaictiu-technicalblog.blogspot.com -
What's the best way to read JSON data?
Hi all;
What is the best way to read in JSON data? And is the best way to use it once read in to turn it into XML and apply XPath?
thanks - davejtahlborn wrote:
without having a better understanding of what your definition of "use it" is, this question is essentially unanswerable. Jackson is a fairly popular library for translating json to/from java objects. the json website provides a very basic library for parsing to/from xml. which one is the "best" depends on what you want to do with it.Good point. We have a reporting product ([www.windward.net|http://www.windward.net]) and we've had a number of people ask us for JSON support. But how complex the data is and what they want to pull is all over the place. The one thing that's commin is they generally want to pull down the JSON data, and then put specific items from that in the report.
XML/XPath struck me as a good way to do this for a couple of reasons. First it seems to map well to the JSON data layout. Second it provides a known query language. Third, we have a really good XPath wizard and we could then use it for JSON also.
??? - thanks - dave -
Best way to read chars from InputStream
Hope this is not a too newbie question.
Suppose I have an unbuffered InputStream inputStream, what is the best way to read chars from it (in terms of performance)?
Reader reader = new BufferedReader(new InputStreamReader(inputStream));
reader.read()
or
Read reader = new InputStreamReader(new BufferedInputStream(inputStream))
reader.read()
Is there a difference between the two and if so, which one is better?
thanks.If you are reading using a buffer of your own, then adding a buffer for binary data is a bad idea.
However for text, using a BufferedInputStream could be better as it reduces calls to the OS.
If it really matters, I suggest you do a simple performance test which runs for at least a few seconds to see what the difference is. (You should runt he test mroe than once)
Edited by: Peter__Lawrey on 20-Feb-2009 21:37 -
What would be the best way to read from a file. Which classes do I need to use?
I have to write a program, which reads data from a comma separated flat file, parse it and after inserting some busineess logic insert into a databse .
I will have to read the data line by line.
Any help????I would use:
public void readData()
try
data = new String[this.countRows("comp.txt")][];
BufferedReader br = new BufferedReader(new FileReader("comp.txt"));
for(int x = 0; x < data.length; x++)
StringTokenizer temp = new StringTokenizer(br.readLine(), "?");
data[x] = new String[temp.countTokens()];
for(int y = 0; y < data[x].length; y++)
data[x][y] = temp.nextToken();
catch(Exception e)
System.out.println(e.toString());
private int countRows(String f)
int t = 0;
try
BufferedReader brCountRows = new BufferedReader(new FileReader(f));
while(brCountRows.readLine() != null)
t++;
catch(Exception e)
System.out.println(e.toString());
return t;
return t;
}It works deliciously! -
Which is the best way for posting a large number of records?
I have around 12000 register to commit to dababase.
Which is the best way for doing it?
What depends on ?
Nowadays I can't commit such a large number of register..The dabatase seems hanged!!!
Thanks in advanceXavi wrote:
Nowadays I can't commit such a large number of registerIt should be possible to insert tens of thousands of rows in a few seconds using an insert statement even with a complex query such as the all_objects view, and commit at the end.
SQL> create table t as select * from all_objects where 0 = 1;
Table created.
Elapsed: 00:00:00.03
SQL> insert into t select * from all_objects;
32151 rows created.
Elapsed: 00:00:09.01
SQL> commit;
Commit complete.
Elapsed: 00:00:00.00
I meant RECORDS instead of REGISTERS.Maybe that is where you are going wrong, records are for putting on turntables. -
Which is the best way of deploying JSP (mod_ose or OSE) ?
I need to deploy some jsps that are using servlet api 2.2 and i would like to know which is the best way of deploying these jsps?
Thanks
RJCSpeaking of JServ Vs OSE, I have some related questions on it. I would appreciate if someone can answer:
1.For a stateful servlet (assuming that we are using Oracle JVM), Will it not call the init() method of the servlet each time for a client (because each client will have his own Oracle JVM)? If so, isn't that expensive because it needs to initialize the servlet again?
Again, for the same servlet, Will it not have a servlet context for each and every client? Isn't that expensive? ( A servlet context by definition maintains state information for all instances of a web application within any single JVM)
2. If we have an application that has some portion of it which is stateless and some portion of it which is stateful, how do we make a choice JDK JVM vs Oracle JVM?
Can we (for the same application) use both the JDK JVM as well as Oracle JVM? If so, how does the JDK JVM talk with Oracle JVM?
3. Since Oracle JVM is useful for stateful applications only, does it mean that we cannot use it for Stateless session beans? (In an application we might have stateless session beans, stateful session beans as well as entity beans) Should we be using JDK JVM or Oracle JVM?
4. For Servlets too, we might have stateless servlets and stateful servlets within the same application. If so, can we use JDK JVM for stateless servlets and Oracle JVM for stateful servlets? If so, how does the JDK JVM talk with Oracle JVM? -
Which is the best way for a called function to identify caller class name.
Which is the best way for a called function to identify the caller class name .
1)Using sun.reflect.Reflection from called function
Class caller = Reflection.getCallerClass(2);
System.out.println("Caller Class Name ::"+caller.getName());2) Analyzing current threads stack trace from called function
StackTraceElement[] stElements=Thread.currentThread().getStackTrace();
System.out.println("Caller Class Name ::"+stElements[3].getClassName());Is there any alternate ways to achieve the same .Which is the best way ?
Called function doesn’t have any arguments, I don’t want t pass any arguments from caller function to called function.
Plz help.
With kind regards
Paul798185 wrote:
Which is the best way for a called function to identify the caller class name .
Is there any alternate ways to achieve the same.SecurityManager
// 0 is the anonymous SecurityManager class
// 1 is this class (also works in static context)
// 2 is calling class
static Class getClass(int i) {
return new SecurityManager() {
protected Class[] getClassContext() {
return super.getClassContext();
}.getClassContext(); -
Filter or Restrict on? Which is the best way to put it?
Hello Experts,
If there is a Characteristic/Key figure on a report in BEx, and I right click on it and find another data element say, 0FISPER it I EDIT. On right click on 0FISPER I a variable.
My question is this, do we way that the key figure is RESTRICTED ON 0FISPER
or, key figure is FILTERED by 0FISPER
When do we use Filter or Restrict on? Which is the best way to put it? How best is it read, please include the variable in your discussion.
I will appreciate this clarification.
e.g. Company code EDIT shows Company codes ZPPTcomp: with nodes 8000, 9000
Thanks.Hi Amanda,
as per my understanding,
you are checking the structure field, you have selected edit then you are viewing a key figure and 0fiscper restricted by varaible. am I right?
if this is the case this is local selection and the key figure is restricted by fiscper variable means the restriction value user can enter in selection screen. if you select 0fiscper and select restrict there you can see single values, value range and you can also see varaible tab. by using varaible tab you can restrict to variable value.
hope this gives you some understanding.
Sathya
Maybe you are looking for
-
Another "An error occurred when attempting to change modules" error
Hello all: After using Adobe Photoshop Lightroom on Mac OSX trouble free for the past 6 months, I opened up Lightroom today and received the following error: "An error occurred when attempting to change modules." I had not made any changes in between
-
How to show Html5 created in eclipse and link to any cloud application like c4C through HCP
Hi Experts, How to show Html5 created in eclipse and link to any cloud application like C4C through HCP Regards, Vijay.
-
ITunes Very Slow to Start Up in Win 8.1 Pro (64-bit)
iTunes has been extremely slow to open when I launch the program, since upgrading to Win 8 (64-bit) (I am now running the latest release of iTunes -- 11.1.4). I went through a number of trial/error "fixes", and I "think" I found the cause -- In Netw
-
Reader 9.3 produces Runtime error for all .pdf files on hard drive and email
Does anyone have a resource that can show me how to eliminate a runtime error with Reader 9.3.1, Windows XP w/ SP3 and IE7. I have recently had all .pdf files located on my hard drive and in emails refuse to open because of this message: "Runtime Err
-
Four GB of user data Limitation in Oracle 10g XE
Hi Mates! There is one limitation in oracle XE which is: It stores up to four GB of user data. I am planning to migrate my database from Oracle 9i to Oracle 10g XE. My queries are below: 1. Is it possible to migrate from Oracle 9i to Oracle 10g XE? 2