Efficieny of this TextFile reader class?
I'm trying to make a class especially for handling text files.
how efficient is this class?
code:
final class TextReader {
public static ArrayList readTextFile(String fileName) {
ArrayList result = new ArrayList();
String tempstr;
try {
FileReader fReader = new FileReader(fileName);
BufferedReader bReader = new BufferedReader(fReader);
while ((tempstr = bReader.readLine()) != null) {
result.add(tempstr);
fReader.close();
} catch (Exception err) {
err.printStackTrace();
return result;
}
Sorry if my question is unclear.
But if you would look at my above implementation, I use static in my method.
So I would call:
ArrayList list = TextReader.readTextFile(textfile);
Or is it better that I leave the static out:
Init(){
TextReader tReader = new TextReader();//empty TextReader constructor
//.......somewhere below
ArrayList list = tReader.readTextFile(textfile);
What I generally want to know is there a better way of implementating a TextReader class than what I did(1 that put a string in an arraylist)?
thx for the replies.
Similar Messages
-
Why do I get this MyClass$1.class
Hello,
I have the following simple class:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class HelloJava2
extends JComponent implements MouseMotionListener {
// Coordinates for the message
int messageX = 125, messageY = 95;
String theMessage;
public HelloJava2(String message) {
theMessage = message;
addMouseMotionListener(this);
public void paintComponent(Graphics g) {
g.drawString(theMessage, messageX, messageY);
public void mouseDragged(MouseEvent e) {
// Save the mouse coordinates and paint the message.
messageX = e.getX( );
messageY = e.getY( );
repaint( );
public void mouseMoved(MouseEvent e) {}
public static void main(String[] args) {
JFrame f = new JFrame("HelloJava2");
// Make the application exit when the window is closed.
f.addWindowListener(new WindowAdapter( ) {
public void windowClosing(WindowEvent we) { System.exit(0); }
f.setSize(300, 300);
f.getContentPane( ).add(new HelloJava2("Hello, Java!"));
f.setVisible(true);
I don't understand what the file called HelloJava2$1.class comes from. There is only one class definition in the source so where does this xx$1.class file comes from?
Thanks in advance,
Balteo.If you wrote it like this:
f.addWindowListener(new MyWindowCloser());
class MyWindowCloser extends WindowAdapter {
public void windowClosing(WindowEvent we) {
System.exit(0);
}then it would be more obvious where the file came from.
These are basicly the same except one can be referenced. -
"Master Data Read Class Parameters" field is disabled
Hi.
While creating infoobject I switch master data access from Default to Own implementation,
after this screen is redisplayed and only Name of Master Data Read Class field become enabled.
I need Master Data Read Class Parameters field, but it is disabled and button near this field has the same status.
Why? How to make them active?Hi,
I think it is not possible to add own Master Data Class if the reference is 0DATE or if the type is DATS.
So may be you can create your infoobject as Type CHAR, Length 8.
May be you can add a Conversion Routine for the required format of date to be displayed. -
8iR3; EJB deploy; "Unable to read class bits" error
Hi,
I have a strange situation going on at the moment. Every time I wish to deploy an EJB to 8iR3, the JDeveloper Message View shows the following (after app specific messages):
"Reading Deployment Descriptor...done
Verifying Deployment Descriptor...done
Gathering users...done
Generating Comm Stubs...............................................done
Compiling Stubs...done
Generating Jar File...done
Loading EJB Jar file and Comm Stubs Jar file...
Unable to read class bits from library/sqlhelper/sjb/SQLHelperOperations.class
*** Errors occurred while deploying the EJB to 8i JVM ***
*** Deployment completed ***
If I then just redeploy without changing a thing, it deploys fine and everything works.
I haven't seen a post on this forum like this, is there a configuration problem at my end?
Cheers,
Jono
nullI think it is due to the fact that I am writing a 'business interface' for my EJB, then including it in my deployment package.
This technique is recommended in O'Reilly's 'Enterprise Java Beans' 2nd Edition p344 to ensure the bean interface and the bean match their signature.
I don't get the 'class bits' error when I write EJB from the wizard, but when I add a business interface it happens first deploy, and is OK for the second one.
Hope this helps anyone else who is getting this behaviour, I guess we'll have to see what happens in OC4J/Orion. -
How to get this type of class?
Hi. I'm trying to make a class like Math which i can run his methods without declaring an object.
I want this:
MyClass.method();
not this:
MyClass a = new MyClass();
a.method();
How can i do it? And what's the name of this type of classes?I have planed to use it with a class which read a text
file like a database and return an object with the
filled fields.
Do you think i should create an instance or with
static methods is right?Without more details, I can't say for sure, but it sounds like something I would do as an instance method, rather than a class (i.e., static) method. The reason to create instances is because they hold state. The satte of an instance of your class might be the file it's responsible for or how big a buffer it has or something. Even if there's no real clear-cut state associated with what you're trying to do, I'd still use instance methods, just to get you into good habits and get practice thinking in OO terms. Resist the temptation to make everything static for now unless you have pure function-like behavior, as the Math class does. -
iOS 7.0.2 seems to make FilemakerGo seize up on startup. How do I report this - I read that I cannot revert to a previous version of iOS on the iPadMini?
Contact the app developer to find out what there recommendations are.
-
Compiling error in my test file for Reader class.
I did a small program trying to test Reader class, here is my code:
package testfilereader;
import java.io.*;
import java.io.Reader;
import java.io.InputStream;
* Title:
* Description:
* Copyright: Copyright (c) 2001
* Company:
* @author
* @version 1.0
public class FileTest {
public static void main(String args[]){
Byte buff[] = new Byte[80];
try{
InputStream r = new FileInputStream("test.txt");
int i = r.read(buff);
String s = new String(buff);
System.out.println(s);
}catch(NullPointerException e){}
catch(IOException e2){}
But I continue to get compiling errors:
C:\>javac FileTest.java
FileTest.java:19: cannot resolve symbol
symbol : method read (java.lang.Byte[])
location: class java.io.InputStream
int i = r.read(buff);
^
FileTest.java:20: cannot resolve symbol
symbol : constructor String (java.lang.Byte[])
location: class java.lang.String
String s = new String(buff);
Please advise what is wrong here.Replace Byte with byte - the methods
expect arrays of byte; not Byte (which is a simple
class wrapper for byte).Hi, I changed to:
byte buff[] = new byte[80];
Same errors, any other ideas? -
HT4489 when i import contact from my pc to icloud he tell me this "proplem reading the vcard"
when i import contact from my pc to icloud he tell me this "proplem reading the vcard"
Recovering your iTunes library from your iPod or iOS device: Apple Support Communities
Also you said " I want to add them to my iCloud, and also back to my computer. " Note that unless subscribe to iTunes match, only iTunes purchases are stored in iCloud.
Also,
You can redownload most iTunes purchases by:
Downloading past purchases from the App Store, iBookstore, and iTunes Store -
Mac OS X cannot install on this computer read install read me on the DVD ?
Bought a used MacBook with a intel Core 2 Duo 2.2 Ghz with 2 gig memory and it came running leopard 10.05.1 on it already want to do a clean install of Leopard. DVD takes me to the point where i chose my language then i get this error saying Mac OS X cannot install on this computer read the install read me on the DVD
Any suggestions ?If this is a retail copy of Mac OS X (not bundled with your mac), that may be the cause of your problem, especially if it was pre-installed with 10.5.1.
As far as I know, but I may be wrong, there is no 10.5.1 retail DVD (only 10.5.0), this could mean your mac is newer than the retail OS X DVD (10.5.0), and you have no other choice that using your Leopard DVD bundled with your machine, because your machine may have some hardware bot handled by the retail 10.5 DVD. -
ClassCastException: You must use ResultSet from this driver!class webl
Hi,
I have configured the Connection pool and DataSources for SQLServer using inet-OPTA
drivers.
I am using the CachedRowSet implementation from inet and it seems to bomb out
with the following error stack trace:
STACK TRACE:
java.lang.ClassCastException: You must use ResultSet from this driver!class webl
ogic.jdbc.rmi.SerialResultSet
at com.inet.tds.CachedRowSet.a(Unknown Source)
at com.inet.tds.CachedRowSet.populate(Unknown Source)
Any ideas of what is causing this problem ?
Is it that i cannot use the CachedRowSet implementation from inet.
If that is the case we have lot of code that uses this and i will have to change
a lot.
Any help is appreciated
Thanks
VenuThe code is in one of the utility classes that is in the classpath and this utility
class is used by the Stateless session EJB that i deployed in the WebLogic AppServer.
As i understand, Weblogic 8.1 is out and i will try running on it.
Thanks
Venu
Joseph Weinstein <[email protected]_this> wrote:
>
>
venu wrote:
Hi,
I am running WebLogic version 7.0.2
Do you have any idea when the 8.1 will be available (i believe it isstill in
beta)
I'll find out. Do answer my other question: Where is this code running
that gets the exception?
Joe
- Srini
Joseph Weinstein <[email protected]_this> wrote:
venu wrote:
Hi,
I have configured the Connection pool and DataSources for SQLServerusing inet-OPTA
drivers.
I am using the CachedRowSet implementation from inet and it seems
to
bomb out
with the following error stack trace:
STACK TRACE:
java.lang.ClassCastException: You must use ResultSet from this driver!classwebl
ogic.jdbc.rmi.SerialResultSet
at com.inet.tds.CachedRowSet.a(Unknown Source)
at com.inet.tds.CachedRowSet.populate(Unknown Source)
Any ideas of what is causing this problem ?
Is it that i cannot use the CachedRowSet implementation from inet.
If that is the case we have lot of code that uses this and i will
have
to change
a lot.
Any help is appreciated
Thanks
VenuHi. What version of the server are you using. This problem will goaway
for 8.1.
We currently wrap all JDBC objects from pooled drivers, to maintaincontrol
over
the pooled connection. Where is this code running that gets the exception.
It seems that Inet's rowset implementation needs to cast the resultset
it gets
to be inet's result set object, in order to make some non-standardmethod
calls.
Joe -
Can any one say, if i should use "this." inside my classes to
refer class
variables and methods? What is its advantage and
disadvantage? Does this
help compiler/flash player in any way.
Provide some useful links which explain this
Cheers,
Sajeevwhen it's appropriate you can use "this". so, if you've just
created a movieclip and you're defining a mouse handler for it,
it's appropriate to use this within the handler's scope.
but to refer to a class member, i use a private variable in
the constructor function to use throughout the class so i don't
have scope issues outside the constructor function. -
Where can I find this standard SAP class?
Hi all,
Which PAR file contains this class:
com.sapportals.wcm.control.search.SearchLanguageControl
It is a standard search component called "search_language". I have two problems with this component:
1. Too many languages are displayed (e.g. Greek and Serbian. However, I don't know why these languages are displayed)
2. I want that the user language is only selected and not the predefined language, too.
Kind regards
Philipp KölschHi,
Refer this link it explain you how to set default language.
http://help.sap.com/saphelp_nw04/helpdata/en/44/e4561731e767d6e10000000a155369/frameset.htm
Regards,
Senthil K. -
Having trouble compiling this file reader program!!
Hi,
I wrote this program to read a flat file so I can parse it thereafter. I'm not sure where I need to change syntax.
If need be, I can send the error msg.
Thanks in advance!!
import java.io.*;
class FileReader1
public String readLine() throws IOException
try {
//FileReader br = new FileReader(new
//File("C:\\Shared CLM\\netsvc.txt")) ;
LineNumberReader lnr = new LineNumberReader(new FileReader(
"C:\\Shared CLM\\netsvc.txt")) ;
String line = lnr.readLine() ;
//switch() {...}
lnr.close() ;
//br.close() ;
} catch (IOException e) {
e.printStackTrace();
}Well, I removed the ";" but I am still getting 9 errors...
C:\mail\CLM Mail Program\Ballb.java:6: ';' expected
public String readLine() throws IOException
^
C:\mail\CLM Mail Program\Ballb.java:6: missing method body, or declare abstract
public String readLine() throws IOException
^
.\FileReader.java:7: ';' expected
public String readLine() throws IOException
^
.\FileReader.java:28: '}' expected
^
.\FileReader.java:7: cannot resolve symbol
symbol : class IOException
location: class FileReader
public String readLine() throws IOException
^
C:\mail\CLM Mail Program\Ballb.java:13: cannot resolve symbol
symbol : constructor FileReader (java.lang.String)
location: class FileReader
{LineNumberReader lnr = new LineNumberReader(new FileReader("C:\\Shared CLM\\netsvc.txt")) ;
^
C:\mail\CLM Mail Program\Ballb.java:14: cannot resolve symbol
symbol : variable line
location: class Ballb
line = lnr.readLine() ;
^
C:\mail\CLM Mail Program\Ballb.java:21: return outside method
return line;
^
.\FileReader.java:7: missing method body, or declare abstract
public String readLine() throws IOException
^
9 errors -
I'd like to do this mapping: one class=one tables !!!
Hello,
I am a new user of kodo, in my application all classes extend my
YOBaseObject class, so when I generate the schema of my msql database
using the mappingTool (as: mappingTool -a refresh package.jdo) only the
table yobaseobject is created.
My gaol is the get one table for a class.
thank you,
smailSmail-
By default, Kodo uses the "flat" class mapping, which stores all of the
subclasses in the table of the top-level persistent class.
You may want to use "vertical" (one table per class in the hierarchy) or
"horizontal" (one table per concrete subclass, no table for abstract
superclass). Take a look at the documentation for the different class
mappings at:
http://docs.solarmetric.com/manual.html#ref_guide_mapping_classmapping
Let us know if you have any questions about any of this.
In article <cc0gr4$iv7$[email protected]>, ouhmmou wrote:
Hello,
I am a new user of kodo, in my application all classes extend my
YOBaseObject class, so when I generate the schema of my msql database
using the mappingTool (as: mappingTool -a refresh package.jdo) only the
table yobaseobject is created.
My gaol is the get one table for a class.
thank you,
smail
Marc Prud'hommeaux
SolarMetric Inc. -
Hi,
I'm presently working in a scenario, where i need to read an XML (having base64 encoded images) using XmlReader class in a streaming fashion (considering the performance) .
1) I have to strip offs the base64 encoded contents from the xml (front & back image node).
2) Than saving the remaining XML (without base64 content) .
Sample XML:-
<?xml version="1.0" encoding="utf-8"?>
<tran>
<tranheader>
<feild1></feild1>
</tranheader>
<item>
<fields></fields>
<image>
<frontimage>base64_content</frontimage>
<rearimage>base64_content</rearimage>
</image>
</item>
<item>
<fields></fields>
<image>
<frontimage>base64_content</frontimage>
<rearimage>base64_content</rearimage>
</image>
</item>
<trantrailer>
<feild1></feild1>
</trantrailer>
</tran>
Please guide.
Thanks & RegardsE.g. a simplified skeleton:
namespace ConsoleCS
using System;
using System.IO;
using System.Xml;
using System.Xml.Linq;
class Program
static void Main(string[] args)
XDocument xdocument = XDocument.Parse(@"
<Items>
<Item>Test with a child element <more/> stuff</Item>
<Item>Test with a CDATA section <![CDATA[<456>]]> def</Item>
<Item>Test with a char entity: A</Item>
<SkipItem>Item to skip.</SkipItem>
<!-- Fourteen chars in this element.-->
<Item>1234567890ABCD</Item>
</Items>");
StringReader stringReader = new StringReader(xdocument.ToString());
XmlReader xmlReader = XmlReader.Create(stringReader);
xmlReader.MoveToContent();
while (xmlReader.Read())
switch (xmlReader.NodeType)
case XmlNodeType.Element:
if (xmlReader.Name == "SkipItem")
Console.WriteLine("Skipping..");
else
Console.WriteLine("Pushing to output ({0}).", xmlReader.Name);
break;
Console.WriteLine("Done.");
Console.ReadLine();
Maybe you are looking for
-
I am trying to activate the root account on my new Mac Book Pro. The instructions that I have found do not match what I have in System Preferences. What is the process when using Users and Groups. When I click on Join the Network Account Server- O
-
I want to send an Image object to a method named insertimage and I don't know how to do it. I have the following lines: import javax.microedition.lcdui.*; import javax.microedition.lcdui.Image; import javax.microedition.midlet.*; public class MiBoton
-
Lost plug-in settings after 7.2 upgrade
Hi after upgrading to 7.2 I seem to have lost Logic's factory presets for it's channel strip settings. On the arrange page, I used to go to the channel strip and click on the "inserts" triangle and one of the options was "factory". This option is no
-
HTTP POST is killing me, please help ...
Hello, I am trying to send an XML file to a php script sitting on a server. I want to do this by HTTP POST through a Java Application. I have the following code developed and haven't an iota why the php script won't pick up the XML file. If anyone ha
-
The way that simulation works is a set of nodal equations is constructed, and then the variables of those equations are solved, including the variables requested by the user, such as via the scope or meters, or as probes in the various analyses. Tha