Reputation: 703
Was thinking of making a program,such that whatsoever I write on a text file ,it should come on the console made this program
import java.io.*;
class Redirector
{
public static void main(String[] args) {
try
{
if(args.length!=1)
{
throw(new Exception("wrong way"));
}
System.setIn(new FileInputStream("b.txt"));
BufferedReader r=new BufferedReader(new InputStreamReader(System.in));
PrintStream x=new PrintStream(new FileOutputStream(args[0]));
System.out.println("enter text,end to terminanate");
while(true)
{
String str=r.readLine();
if(!str.equalsIgnoreCase("end"))
System.out.println(str);
else
break;
}
System.out.println("done");
}
catch(Exception e)
{
System.out.println(e);
}
}
}
but the problem is that I want the whatsoever I write dynamically on the file and press enter should come on the console,whereas in this case it should be saved
Upvotes: 0
Views: 60
Reputation: 2124
What you're asking for is not possible. As long as you don't save the text file, its contents are not actually on the disk, they're only in memory.
You could theoretically try to access it in the allocated memory of whatever program you're using to edit the text file, but this is very difficult as it would require knowing the layout of its memory chunk. Moreover, it is a huge security risk, so most modern operating systems will make very sure you can't do it.
Upvotes: 4