|
I'm glad to see the local Hungarian IT guru has undeaded your laptop.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Nope. I was/am at work.
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
|
Hi , ANYONE LET ME KNOW WHAT IS GOING WRONG HER, I AM TRYING TO CREATE ZIP FILE IN JAVA, BUE IAM GETTING THE ERROR AS FALLOWS, GO THRU THE CODE ALSO WHAT I WROTE
import java.util.zip.*;import java.io.*;
public class ZipFileExample {
public static void main(String args[])throws IOException {
FileInputStream fis=new FileInputStream("Allpaths.txt");
FileOutputStream fos=new FileOutputStream("kkk.txt");
DeflaterOutputStream dos=new DeflaterOutputStream(fos);
int data;
while((data=fis.read())!=-1){
dos.write(data);
fis.close();
dos.close();
}
}
}
eRROR: Exception in thread "main" java.io.FileNotFoundException: Allpaths.txt (The system cannot find the file specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(Unknown Source)
at java.io.FileInputStream.<init>(Unknown Source)
at ZipFileExample.main(ZipFileExample.java:4)
modified on Thursday, July 16, 2009 11:06 PM
|
|
|
|
|
Hi, please check your Caps lock. And use pre tags.
Anyway, are you sure "Allpaths.txt" exists?
Of course you are, otherwise you wouldn't be posting here with ALL CAPS, but would you check it again?
And that while loop looks fishy. Where is the closing }? I think it should be after the dos.write, but in this case you would accomplish the same by removing the opening {. This shouldn't even compile, but putting the } after dos.close is pretty much guaranteed to be wrong.
|
|
|
|
|
i closed properlly, eventhough iam getting same problem
|
|
|
|
|
chinnasri wrote: i closed properlly
No you didn't, you only closed in a way that would compile, not in the way that you should close.
But anyway, the problem is not caused by the weird closing - the problem happens before that. But if you don't fix the closing, it will be your next problem. Or maybe there will be something in between, but eventually it will be a problem if you leave it like this.
Please verify that the file that you are opening actually exists.
|
|
|
|
|
The documentation for FileInputStream is very clear, if you read it:
If the named file does not exist, is a directory rather than a regular file, or for some other reason cannot be opened for reading then a FileNotFoundException is thrown.
So, either make sure that Allpaths.txt is in the classpath for your application, or specify the full path to its location.
Your while loop is wrong. You close the input stream during the first iteration through the loop, immediately after writing to the deflater. So, the second time you try to read from it, it will fail because it is no longer open.
|
|
|
|
|
Hi Pals
This is my first post here in the forum. I've written a program which will compare two integer variables and display output. I have implemented Inheritance in the program. Here is the code:
package Demo;
public class A {
public int a;
public int b;
public A() {}
}
class B extends A{
int a1;
int b1;
public int M1(int a)
{
a1=a;
return a1;
}
public int M2(int b){
b1=b;
return b1;
}
}
class C extends B{
public void Compare(){
if (a1<b1)
{
System.out.println("The value:"+a1+" is smaller than:"+b1);
}
System.out.println("The value:"+b1+" is smaller than:"+a1);
}
}
class D{
public static void main(String args[])
{
B b=new B();
b.M1(50);
b.M2(100);
C c=new C();
c.Compare();
}
}
However, I get Logical error as this:
The value: 0 is smaller than: 0
This is incorrect, since I am passing values through the parameterized function call I am making to Methods: M1 and M2, in the main Method.
Please help me with a solution.
Help will be much appreciated,
Rajdeep.NET
(I will change that .NET surname to .JAVA soon)
I calculate my days on earth..... approximately 55 years remaining for me to expire
modified on Wednesday, July 15, 2009 1:52 PM
|
|
|
|
|
Rajdeep.NET wrote:
B b=new B();
b.M1(50);
b.M2(100);
C c=new C();
c.Compare();
You create two instances. In the 'c' instance you do not set M1 or M2.
C c = new C();
c.M1(50);
c.M2(100);
c.Compare();
If at first you don't succeed, you're not Chuck Norris.
|
|
|
|
|
Thanks Fly,
That was a silly mistake.
I calculate my days on earth..... approximately 55 years remaining for me to expire
|
|
|
|
|
0. Don't you dare even think you are a java monkey, let alone a guru!
1. Read the documentation from Sun. It's ALL online and FREE, you have no excuse.
2. Though not reserved the Compare() method is part of the Comparable interface; read all about it here[^].
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
Jack of all trades, master of none
If at first you don't succeed, you're not Chuck Norris.
|
|
|
|
|
??? Who ???
I are master of loadsatrades - plumber, painter, gardner, chef and occasional code-monk.
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
Nagy Vilmos wrote: ??? Who ???
'it'
If at first you don't succeed, you're not Chuck Norris.
|
|
|
|
|
i'm trying to read an xml file in java webservice,but the problem is even though the path is given it always searches the
"c:\programfiles\glassfish2\domains\domain1\config"
how can i give the path for the xml file in the project folder .
|
|
|
|
|
I want to know the restrictions imposed by a java applet on general programming with java. Basically I want to understand things we can do and things we cannot do...you know, where I might hit the silver lining?
PS: I am not so proficient in java technologies
|
|
|
|
|
This is the 'executive summary'
From memory and without bothering to search, a java applet cannot [should not?] go outside of the JVM except to 'phone home'. There is or should be no local IO.
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
There is a java applet capable of reading the mac address. How do you think a browser application would be able to achieve this?
|
|
|
|
|
Getting your applet signed (such as by Verisign) can increase the things you are allowed to do by giving you a little more access to things outside of the 'sandbox'. Getting your applet signed does cost money...
|
|
|
|
|
Hello All,
I am using rxtxSerial library (import gnu.io.*; ) for my bridge application. Th example provided in the library's web site with nulltest.java employs only one serial port. It is powerful since it is threaded and detects incomming/outgoing streams.
However, I would like to bridge between servers so multiple ports will be employed. Do you heave any suggestion how to obtain it. The null test code is presented as follows.
import java.io.*;
import java.util.*;
import gnu.io.*;
public class nulltest implements Runnable, SerialPortEventListener {
static CommPortIdentifier portId;
static CommPortIdentifier saveportId;
static Enumeration portList;
InputStream inputStream;
SerialPort serialPort;
Thread readThread;
static String messageString = "AT";
static OutputStream outputStream;
static boolean outputBufferEmptyFlag = false;
public static void main(String[] args) {
boolean portFound = false;
String defaultPort;
String osname = System.getProperty("os.name","").toLowerCase();
if ( osname.startsWith("windows") ) {
defaultPort = "COM5";
} else if (osname.startsWith("linux")) {
defaultPort = "/dev/ttyS0";
} else if ( osname.startsWith("mac") ) {
defaultPort = "????";
} else {
System.out.println("Sorry, your operating system is not supported");
return;
}
if (args.length > 0) {
defaultPort = args[0];
}
System.out.println("Set default port to "+defaultPort);
portList = CommPortIdentifier.getPortIdentifiers();
while (portList.hasMoreElements()) {
portId = (CommPortIdentifier) portList.nextElement();
if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
if (portId.getName().equals(defaultPort)) {
System.out.println("Found port: "+defaultPort);
portFound = true;
nulltest reader = new nulltest();
}
}
}
if (!portFound) {
System.out.println("port " + defaultPort + " not found.");
}
}
public void initwritetoport() {
try {
outputStream = serialPort.getOutputStream();
} catch (IOException e) {}
try {
serialPort.notifyOnOutputEmpty(true);
} catch (Exception e) {
System.out.println("Error setting event notification");
System.out.println(e.toString());
System.exit(-1);
}
}
public void writetoport() {
System.out.println("Writing \""+messageString+"\" to "+serialPort.getName());
try {
outputStream.write(messageString.getBytes());
} catch (IOException e) {}
}
public nulltest() {
try {
serialPort = (SerialPort) portId.open("SimpleReadApp", 2000);
} catch (PortInUseException e) {}
try {
inputStream = serialPort.getInputStream();
} catch (IOException e) {}
try {
serialPort.addEventListener(this);
} catch (TooManyListenersException e) {}
serialPort.notifyOnDataAvailable(true);
try {
serialPort.setSerialPortParams(9600, SerialPort.DATABITS_8,
SerialPort.STOPBITS_1,
SerialPort.PARITY_NONE);
} catch (UnsupportedCommOperationException e) {}
readThread = new Thread(this);
readThread.start();
}
public void run() {
initwritetoport();
try {
while (true) {
writetoport();
Thread.sleep(1000);
}
} catch (InterruptedException e) {}
}
public void serialEvent(SerialPortEvent event) {
switch (event.getEventType()) {
case SerialPortEvent.BI:
case SerialPortEvent.OE:
case SerialPortEvent.FE:
case SerialPortEvent.PE:
case SerialPortEvent.CD:
case SerialPortEvent.CTS:
case SerialPortEvent.DSR:
case SerialPortEvent.RI:
case SerialPortEvent.OUTPUT_BUFFER_EMPTY:
break;
case SerialPortEvent.DATA_AVAILABLE:
byte[] readBuffer = new byte[20];
int numBytes = 0;
try {
while (inputStream.available() > 0) {
numBytes = inputStream.read(readBuffer);
}
String result = new String(readBuffer);
System.out.println("Bytes read: "+numBytes+", Read contents: "+result);
} catch (IOException e) {}
break;
}
}
}
Kujtim
|
|
|
|
|
Sir, This is maheswara from A.P ...where can i get the code for band width analysis i.e it should record sent data and received data in a system with internet connection ....we have spent almost 10 days but no result plzzzzzzzz
|
|
|
|
|
Hey Maheshwara,
Nice to know that you are from A.P. But nobody (except indians) would know about that place. Well yes, and about your question, I think Google search does everything. Learn to use google to search for core programming resources sweetheart.
And how's Cheeranjivi? When is his next film gonna release?
I calculate my days on earth..... approximately 55 years remaining for me to expire
|
|
|
|
|
Hello,
I heave an array of objects which each object has some common parameters, but also is to be characterized by adequate specific object. For each object I use 'objectType' parammeter to differentiate, then the rest, I tried as follows (using 'Object' type) but it is not working. Here is the complete simplified code:
class DiffObjectClasses{
public static void main(String [] args)
{
SerialObject so;
IPObject iob;
ObjectType ot[] = new ObjectType[3];
ot[0].objectID=1;
ot[0].objectType=1;
so=new SerialObject();
so.serialPortNo=21;
ot[0].objectContent=so;
ot[1].objectID=2;
ot[1].objectType=1;
so=new SerialObject();
so.serialPortNo=21;
ot[1].objectContent=so;
ot[2].objectID=3;
ot[2].objectType=2;
iob=new IPObject();
iob.host="localhost";
iob.port=2200;
ot[2].objectContent=iob;
System.out.println("----------------------------");
for(int indx=0; indx<ot.length;indx++)
{
System.out.println("ObjID:"+ot[indx].objectID);
System.out.println("ObjType:"+ot[indx].objectType);
switch(ot[indx].objectType)
{
case 1:
so=(SerialObject)ot[indx].objectContent;
System.out.println("Serial port no:"+so.serialPortNo);
break;
case 2:
iob=(IPObject)ot[indx].objectContent;
System.out.println("IP host:"+iob.host);
System.out.println("IP port:"+iob.port);
break;
}
}
}
}
class ObjectType{
int objectID;
int objectType;
Object objectContent;
}
class SerialObject{
int serialPortNo;
}
class IPObject{
String host="";
int port;
}
I've worked in C/C++, it was very simple by declaring 'void' member and then using implicit conversion as here but it sin't working in Java.
Kujtim
|
|
|
|
|
If you declare those last two classes like so:
class SerialObject extends ObjectType{
int serialPortNo;
}
class IPObject extends ObjectType{
String host="";
int port;
}
It may work.
You generally can't cast types to each other unless they somehow derive from each other in some way (unless it's a primitive type)
|
|
|
|