java - File content redirection to args doesn't works -
i testing little piece of code need implement in java school project.
public class prova { public static void main(string[] args){ system.out.println(args.length); for(int = 0; < args.length; i++){ system.out.print(args[i]); } system.out.print("\nend!"); } }
when type in console java prova < test.dot
while content of test.dot
file is:
digraph g1 { c -> e; -> e; -> f; f -> b; g; }
i this:
c:\users\lorenzo\workspace\progetto_asd\bin>java prova < test.dot 0 end!
i tryed java prova > output.txt
see if pipe worked , (i same above in file).
if try type test.dot
get:
c:\users\lorenzo\workspace\progetto_asd\bin>type test.dot digraph g1 { c -> e; -> e; -> f; f -> b; g; }
as expect.
i don't know what's wrong i'm doing (i'm using windows way).
you mixing 2 different approaches:
args
you should run program
java prova arg1 arg2 ... argn
:java prova "digraph g1 {" "c -> e;" "a -> e;" "a -> f;" "f -> b;" g; }
and want change
system.out.print(args[i]);
to
system.out.println(args[i]);
to have 7 different lines.
redirection
this equivalent program accepts input keyboard. can change program this:
import java.io.bufferedreader; import java.io.ioexception; import java.io.inputstreamreader; public class prova { public static void main(string[] args) { bufferedreader br = new bufferedreader(new inputstreamreader(system.in)); string line; try { while ((line = br.readline()) != null) { system.out.println(line); } } catch (ioexception e) { e.printstacktrace(); } } }
and call
java prova < test.dot
.
Comments
Post a Comment