The following are some programs that are used for accessing the files in Java.
Write and Run a command file with PrintWriter :
Code:
Main.java
public class Main
(Public static void main (final java.lang.String [] args)
throws java.lang.Throwable
(Final java.io.File outFile = new java.io.File ("generated.bat");
final java.io. PrintWriter out =
new java.io.PrintWriter (new java.io.FileOutputStream (outFile), true);
for (int i = 0; i <60; + + i) out. println
("Wget http://www.example.com/resource" + i + ". Text");
out. close ();
if (java.awt.Desktop.isDesktopSupported ())
java.awt.Desktop.getDesktop (). open (outFile);))
Reading lines with scanner (fragments) :
Code:
Fragment
wordStream = new java.io.FileInputStream ("C: / R/n/S/WINDOWS/Desktop/it16000.txt");
wordScanner = new java.util.Scanner (wordStream);
while (wordScanner. hasNextLine ())
(Final java.lang.String Wordline = wordScanner. NextLine ();)
Fragment
final int number = new java.util.Scanner ("I have nine peanuts"). skip ("\ \ D +"). nextInt ();
Fragment
scanner. skip ("References:");
scanner. useDelimiter ("[\ t \ r \ n] +");
S.nextInt System.out.println (());
S.nextInt System.out.println (());
S.next System.out.println (());
S.next System.out.println (());
Fragment
if (scanner. hasNextInt ())
(Final int i = scanner. NextInt ();)
Fragment
if (hasNext scanner. ("<[^>]+>"))
(Final java.lang.String to = scanner. Next ("<[^>]+>");)
Bookmarks