|
I don't find a suitable method to write ArrayLists to a text file. Does each attribute of the class objects that make up the ArrayList have to be written separately? When I wriye the class object of the ArrayList, it just writes out the memory location. Any advice would be much appreciated.
Thank you.
AF Pilot
|
|
|
|
|
you have to loop through the array list and get each array and print it through loop two
for example
private void printArryList(ArrayList<string[]>someList)
{
int counter=0;
for (int i = 0; i < someList.size(); i++) {
System.out.print("["+(++counter)+"]");
for (int j = 0; j < someList.get(i).length; j++) {
System.out.print(someList.get(i)[j]+" ");
}
System.out.println();
}
}
|
|
|
|
|
Thank you very much. I couldn't find much about writing out an ArrayList to a file in any of the Java documentation or tutorials (that appeared understandable to me, anyway). Much appreciated.
AF Pilot
|
|
|
|
|
Hello Friends,
I am looking for a solution to extract following meta data information from WMV file
1. Width
2. Height
3. Duration
4. Bit Rate
Can anyone please suggest me how I can start my RnD journey to achieve this solution.
Any help would be highly appreciated.
Thank You,
Java Developer - First Time
|
|
|
|
|
i dont know the exact program , but still i use Mediainfo . To download mediainfo.exe it will shows bitrate , size,bandwodth .. etc..
Thanks
mani.G
|
|
|
|
|
You need to learn about the format itself. Try Wikipedia for starters:
http://en.wikipedia.org/wiki/Windows_Media_Video[^]
Once you know the format, you'll need to look into Java file handling routines.
Don't let my name fool you. That's my job.
|
|
|
|
|
Hello guys
i am new to java and i have some problem that going to make my head explode
i am stuck on this thing for a week now
i need to read data file by column not by lines
for example
i have the following data file
6, 148, 72, 35, 0, 336, 0627, 50, 2
8, 183, 64, 0, 0, 233, 0672, 32, 2
1, 85, 66, 29
1, 89, 66, 23, 94, 281, 0167, 21, 1
0, 137, 40, 35, 168, 431, 2288, 33, 2, 10, 9, 125
5, 116, 74, 0, 0, 256, 0201, 30, 1
i need to read it coulmn by coulmn and store it to arrays
for exaample the first array would be {6,8,1,1,0,5} and so on
all what i have done is read it line by line and thats not working for me
this what i've done so far
public class VariableTransformation
{
private String FileName = "";
private FileReader FileReader;
private BufferedReader buffFile;
private ArrayList<string[]> attrDomainList = new ArrayList<string[]>();
private String[] item=null;
public static void main(String[] args)
{
VariableTransformation tds = new VariableTransformation();
Scanner input=new Scanner(System.in);
System.out.println("===============================================");
System.out.print("Enter the file name>> ");
String filename;
filename=input.next();
tds.fileLoad(filename);
System.out.println("===============================================");
}
public void fileLoad(String fileName)
{
String line = "";
String[] attrDomain;
FileName = fileName;
System.out.println("> Reading File..");
try {
int lineCount=0;
int size=0;
FileReader = new FileReader(FileName);
buffFile = new BufferedReader(FileReader);
try {
while((line = buffFile.readLine()) != null)
{
item = line.split(",");
size=item.length;
attrDomain=new String[size];
for (int i = 0; i < item.length; i++) {
attrDomain[i]=item[i];
}
attrDomainList.add(attrDomain);
lineCount++;
}
printData(attrDomainList);
System.out.println("> Finish File Reading.");
System.out.println("Number of Lines>> "+lineCount);
System.out.println("===============================================");
}
catch (IOException e) {
System.out.println(e.getStackTrace().toString());
System.out.println("# Error while reading file .");
}
finally
{
try {buffFile.close();} catch (IOException e) {e.printStackTrace();}
try {FileReader.close();} catch (IOException e) {e.printStackTrace();}
}
} catch (FileNotFoundException e) {
System.out.println("> Error. Target File Don't exist.");
e.printStackTrace();
}
}
private void printData(ArrayList<string[]> dataFile )
{
int Counter=0;
for (int i = 0; i < dataFile.size(); i++) {
System.out.print("["+(++Counter)+"] ");
for (int j = 0; j < dataFile.get(i).length; j++) {
System.out.print(dataFile.get(i)[j]+" ");
}
}
}
}
HELP PLEASE
|
|
|
|
|
|
you're on a forum for help about Java programming... so, what's your question ?
|
|
|
|
|
My question was what Java-programmers think about unusual approach to Java-programming which is described in the article above
|
|
|
|
|
On other forums, this might get modded down as "Unworthy Self Link". I think you should not have posted it here.
As for the article, a brief skimming leaves me quite confused. I think you need more organization. At what point do you show how to write C-style programs? And why do you think those are different from Java, which is already C-style?
Are you planning to write a big main() block of straight line code? I do not see the advantage of that. Teaching bad coding practices to Java beginners seems like a really inappropriate thing to do.
Don't let my name fool you. That's my job.
|
|
|
|
|
I make an excuse for tempering you (as the other forum members) for advertising my article. It is not because lack of modesty but more because I am very old programmer and still consider all kind of forums as public bulletin boards. The times changed, I see it now. The article is addressed to MPU-programmers, who know classical C and don't want to learn Java. The problem is: simple and cheap Cellular Phone is very userful device for MPU-programmes but its software includes only J2ME. I suggest the way for them to use Cell Phone (not Java) as device communicating with MPU's. I posted my link on Java pages to get professional critics of my sourse-code which to my mind has many interresting solutions. I had no intention to teach Java programmers.
|
|
|
|
|
or even further to my BBS days, cross-posting in inappropriate forums was still a big no-no.
I suppose you may have come from pre-Darpanet days when there were no such things as topics. Maybe while you were dodging dinosaurs you'd post wherever you could as fast as possible, just in case a sabre tooth tiger came along or a mammoth tromped on you.
But, yeah, even the earliest versions of America Online had rules. Somehow you missed those...
Don't let my name fool you. That's my job.
|
|
|
|
|
Here's what I'm using to change out the image content in an iframe,
client really needs to have each image linkable, is it possible to add a url variable and array to make each image on click go to a specific URL?
Tryed a few things with my limited java knowledge and can't seem to make it happen.
Any help/suggestions wickedly appreciated!
Script:
<script type="text/javascript">
<!--
function showImage(imgName) {
var curImage = document.getElementById('screenImg');
var curUrl = document.getElementById('screenUrl');
var thePath = 'img/';
var theSource = thePath + imgName;
var theTarget = 'screenImg'
curImage.src = theSource;
curImage.alt = imgName;
curImage.title = imgName;
curImage.target = imgTarget;
}
//-->
</script>
Html:
<iframe src="img/image1.jpg" width="500" height="200" frameborder="0" marginwidth="0" marginheight="0" scrolling="no" name="screenImg" id="screenImg" class="scframe"></iframe>
<a href="#" onMouseOver="showImage('image1.jpg');">Link 1</a><br />
<a href="#" onMouseOver="showImage('image2.jpg');">Link 2</a><br />
<a href="#" onMouseOver="showImage('image3.jpg');">Link 3</a><br />
<a href="#" onMouseOver="showImage('image4.jpg');">Link 4</a><br />
<div class="ForumMod">modified on Wednesday, January 14, 2009 2:41 PM</div>
|
|
|
|
|
|
HI,
I am using Javascript for bookmark in my project.Here is the code
function prepBookmarkLink() {
if (window.sidebar && window.opera && window.print) {
var bkmkLink = document.getElementById('bookmarkLink');
// bkmkLink.rel = 'sidebar';
// bkmkLink.href = location.href;
// bkmkLink.title = document.title;
// bkmkLink.setAttribute('href',document.URL);
// bkmkLink.setAttribute('title',document.title);
// bkmkLink.setAttribute('rel','sidebar');
// bkmkLink.click();
}
}
function bookmark(){
var title = document.title;
var url= document.URL;
var ua=navigator.userAgent.toLowerCase();
var isKonq=(ua.indexOf('konqueror')!=-1);
var isSafari=(ua.indexOf('webkit')!=-1);
var isMac=(ua.indexOf('mac')!=-1);
var buttonStr=isMac?'Command/Cmd':'CTRL';
if(window.sidebar){
window.sidebar.addPanel(title,url,"");
}
else if(window.opera && window.print) {
prepBookmarkLink();
// (document.write('<a href ="javascript:bookmark()");">Add Bookmark</a>'));
var elem = document.createElement('a');
elem.setAttribute('href',url);
elem.setAttribute('title',title);
elem.setAttribute('rel','sidebar');
elem.click();
// var a=document.createElement('a');
// a.href=location.href;
//
//
// a.rel='sidebar'; // this makes it work in Opera 7+
// a.click();
//
// a.title=document.title;
// return cont.appendChild(a);
// //
document.write('<a href = "'+url+'" title="'+title+'" rel="sidebar">Bookmark Site</a>');
alert('test');
}
else if(window.external && (!document.createTextNode ||
(typeof(window.external.AddFavorite)=='unknown'))) {
// IE4/Win generates an error when you
// execute "typeof(window.external.AddFavorite)"
// In IE7 the page must be from a web server, not directly from a local
// file system, otherwise, you will get a permission denied error.
window.external.AddFavorite(url, title); // IE/Win
} else if(isKonq) {
alert('You need to press CTRL + B to bookmark our site.');
} else if(window.opera) {
alert("dfsdf");
void(0); // do nothing here (Opera 7+)
//return true;
} else if(window.home || isSafari) { // Firefox, Netscape, Safari, iCab
alert('You need to press '+buttonStr+' + D to bookmark our site.');
} else if(!window.print || isMac) { // IE5/Mac and Safari 1.0
alert('You need to press Command/Cmd + D to bookmark our site.');
} else {
alert('In order to bookmark this site you need to do so manually '+
'through your browser.');
}
}
|
|
|
|
|
1) you don't follow the posting guidelines and the messages formatting rules.
2) this is not Java, it is Javascript, so ask the right forum if you want to get relevant answers about this.
Also, I'm sure google knows plenty of cross-browsers working solutions
|
|
|
|
|
I've got an Object array that holds various types of objects. I'm trying to code up some sort of parameterized class or method that will print the contents of those objects.
This array belongs to the framework, and is populated accordingly before a notification routine is called. For example, if the notification routine is called with a value of 100, I know the array contains Orange objects, if it is called with a value of 200, I know the array contains Apple objects, etc. In the notification routine, I need to call a "print" function that will print the contents of the object regardless of its type.
Here's how I am currently doing it:
case 100:
Orange orange = (Orange) m_objectNames[0].getListObject();
printContents(new Orange(), m_objectNames);
break;
case 200:
Apple Apple = (Apple) m_objectNames[0].getListObject();
printContents(new Apple(), m_objectNames);
break; Is this clear as mud? My print function looks like:
public static <T> int printContents( T t, ObjectName objNames[] )
{
for (int x = 0; x < objNames.length; x++)
t = (T) objNames[x].getListObject();
} The loop runs the correct number of times, but I can't figure out how to access the methods and properties of the T objects.
- DC
"Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
|
|
|
|
|
Hi David, coding java now ?! ^^
well, you're not really facing a Java problem, but more a polymorphism one IMO.
as long as you're handling a T (generic class), you cannot guess which methods to call...
the only thing which can be done is calling a method which is in every classes, by telling T is an interface (or an abstract base class)...
|
|
|
|
|
toxcct wrote: Hi David, coding java now ?! ^^
Yes, and have been for nearly two years now. It's been an enjoyable change.
What I have since found out is that I can use instanceof on the objects in the ObjectName[] array. It correctly reports them as being Apple, Orange, Truck, etc. My print routine now looks like:
public void printContents( ObjectName objectNames[] )
{
if (objectNames[0] instanceof Apple)
...
else if (objectNames[0] instanceof Orange)
...
else if (objectNames[0] instanceof Truck)
...
}
"Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
|
|
|
|
|
hum, yes, I thought of that way, but since reflexion is performance consuming (IIRC), I always prefer using "regular" OOP, not tricky solution, but it's true, you can to this (and explicit cast back to the actual type before calling methods)...
|
|
|
|
|
toxcct wrote: ...I always prefer using "regular" OOP, not tricky solution...
What did you have in mind?
"Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
|
|
|
|
|
class Fruit{}
class Orange extends Fruit {}
class Banana extends Fruit {}
|
|
|
|
|
In reality, that is what I have in place:
class InfoBase
{
}
class MessageBase extends InfoBase
{
String strDate;
String strTime;
}
class RecipientBase extends InfoBase
{
String strName;
}
"Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
|
|
|
|
|
Somewhere at home I have a wicked cool printing function that I tweaked from the original code, taken from an online article. I even got the author to suggest some improvements. Unfortunately, I'm at work and the whole thing is based on reflection.
What you seem to want is to override the toString() method.
By default, your objects will use Object.toString(), which merely prints out a hash code or some such. Not very useful for complex requirements.
Override it in your Fruit InfoBase class to print out whatever it is you want. Then, override it again in the subclasses only if you have special changes that the super class cannot see.
[Edited: just realized Fruit was not your class.]
If you want a one-size fits all solution, however, you'll definitely need reflection. If I remember to look tonight, I'll see if I can find that class.
Don't let my name fool you. That's my job.
modified on Monday, February 9, 2009 9:30 PM
|
|
|
|
|