Hi Friends,
I have written code in Java to demonstrate pipes for I/O. When I compile the program, it gives me an error about the IO. The message stats that it cannot resolve symbol. I need your help. Please help me as soon as possible..!!
Hi Friends,
I have written code in Java to demonstrate pipes for I/O. When I compile the program, it gives me an error about the IO. The message stats that it cannot resolve symbol. I need your help. Please help me as soon as possible..!!
Signatures reduce available bandwidth
What exactly are you getting the I/O Error message.? Are you getting the message "I/O Exception while Reading, Connection refused" ?? Because this is the commonly generating I/O error message. If you are getting this message which indicates that there's no server responding at all. So you will have to check the Server first. Also try to correct the IP address of server. If there is any Firewall working, then try to stop that service. Because many times the firewalls cause the issue.
You mentioned that you are writing code in Java to demonstrate pipes for I/O. I am not able to get your Question properly.!! I know the meaning of the Pipe. A pipe in Java can be defined as an input/output link between two programs, commonly where you use the output from one program as the input for another program. And a broken pipe means that the linkage between the output and input is interrupted. You may get problems with the amount of swap file storage or overall memory usage approaches its limits. I think that if you provide the code for that will be much better.!! Then we can troubleshoot the coding much easily.
Thanks for replying me Friends,
Here is my code that I have written :
import java.io.*;
class PipeApp
{
public static void main(String[] args)
{
PipeApp pipeApp = new PipeApp();
try
{
FileInputStream AFileIn = new FileInputStream("input.txt");
InputStream BInPipe = pipeApp.changeToB(AFileIn);
InputStream CInPipe = pipeApp.changeToC(BInPipe);
System.out.println();
System.out.println("Here is the results:");
System.out.println();
BufferedReader inputStream = new BufferedReader(new InputStreamReader(CInPipe));
String str = inputStream.readLine();
while (str != null)
{
System.out.println(str);
str = inputStream.readLine();
}
inputStream.close();
}
catch (InterruptedException e)
{
System.out.println(e.toString());
}
}
public InputStream changeToB(InputStream inputStream)
{
try
{
BufferedReader AFileIn = new BufferedReader(new InputStreamReader(inputStream));
PipedOutputStream pipeOut = new PipedOutputStream();
PipedInputStream pipeIn = new PipedInputStream(pipeOut);
PrintStream printStream = new PrintStream(pipeOut);
Thread bThread = new Thread(AFileIn, printStream);
bThread.start();
return pipeIn;
}
catch (InterruptedException e)
{
System.out.println(e.toString());
}
return null;
}
public InputStream changeToC(InputStream inputStream)
{
try
{
BufferedReader BFileIn = new BufferedReader(new InputStreamReader(inputStream));
PipedOutputStream pipeOut2 = new PipedOutputStream();
PipedInputStream pipeIn2 = new PipedInputStream(pipeOut2);
PrintStream printStream2 = new PrintStream(pipeOut2);
Thread cThread = new Thread(BFileIn, printStream2);
cThread.start();
return pipeIn2;
}
catch (InterruptedException e)
{
System.out.println(e.toString());
}
return null;
}
}
In following two lines :
Thread bThread = new Thread(AfileIn, printStream2);
and
Thread cThread = new Thread(BfileIn, printStream2);
I keep getting an error. I remember being told that the first error is usually the error and those are the only two errors I get or else I may have messed up elsewhere. Please help me out..!!
Signatures reduce available bandwidth
Hi 'Viensterrr', as you stated the error message, from the compiler the first error message was :
PipeApp.java:42: cannot resolve symbol
symbol : constructor Thread (java.io.BufferedReader,java.io.PrintStream)
location: class java.lang.Thread
Thread bThread = new Thread(AFileIn, printStream);
Now after seeing this I think that it has a problem with 'constructor Thread (java.io.BufferedReader,java.io.PrintStream)'. there is no Thread() constructor. There should be the Thread() constructor that takes java.io.BufferedReader and java.io.PrintStream as arguments. Hope that you can now resolve the error.
First of all you haven't defined a run() method used by the threads. Also I think that, you will have to throw IOException in the method when you are using the java.io.* package in which you are using it. The code should be :
import java.io.*
public class example
{
public static void main(String [] args) throws IOException
{
All you code goes here
}
}
Hope that using the IOException will help you to isolate the problem.
Bookmarks