MY application code does not work on the Java Wireless Toolkit-
import java.io.*;
public Write{
public static void main(String[] args) throws IOException{
BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); System.out.print("Please enter the file name to create : "); String file_name = in.readLine(); File file = new File(file_name); boolean exist = file.createNewFile(); if (!exist) { System.out.println("File already exists."); System.exit(0); } else { FileWriter fstream = new FileWriter(file_name); BufferedWriter out = new BufferedWriter(fstream); out.write(in.readLine()); out.close(); System.out.println("File created successfully."); }
} } this indicates error :::::::->
Project "Numune7" loaded
Project settings saved
Building "Numune7"
C:\WTK23\apps\Numune7\src\Write.java:3: class or interface expected
public Write{
^
C:\WTK23\apps\Numune7\src\Write.java:5: class or interface expected
public static void main(String[] args) throws IOException{
^
C:\WTK23\apps\Numune7\src\Write.java:7: class or interface expected
System.out.print("Please enter the file name to create : "); ^
C:\WTK23\apps\Numune7\src\Write.java:8: class or interface expected
String file_name = in.readLine(); ^
C:\WTK23\apps\Numune7\src\Write.java:9: class or interface expected
File file = new File(file_name); ^
C:\WTK23\apps\Numune7\src\Write.java:10: class or interface expected
boolean exist = file.createNewFile(); ^
C:\WTK23\apps\Numune7\src\Write.java:11: class or interface expected
if (!exist) ^
C:\WTK23\apps\Numune7\src\Write.java:14: class or interface expected System.exit(0);
^
C:\WTK23\apps\Numune7\src\Write.java:15: class or interface expected
} ^
C:\WTK23\apps\Numune7\src\Write.java:19: class or interface expected
BufferedWriter out = new BufferedWriter(fstream); ^
C:\WTK23\apps\Numune7\src\Write.java:20: class or interface expected
out.write(in.readLine()); ^
C:\WTK23\apps\Numune7\src\Write.java:21: class or interface expected out.close();
^
C:\WTK23\apps\Numune7\src\Write.java:22: class or interface expected
System.out.println("File created successfully."); ^
C:\WTK23\apps\Numune7\src\Write.java:23: class or interface expected } ^ 14 errors com.sun.kvem.ktools.ExecutionException
Build failed Running with storage root DefaultColorPhone
Running with locale: Russian_Russia.1251
Unable to create MIDlet Write
java.lang.ClassNotFoundException: Write
at com.sun.midp.midlet.MIDletState.createMIDlet(+29) at com.sun.midp.midlet.Selector.run(+22)
Execution completed.
918411 bytecodes executed
30 thread switches
893 classes in the system (including system classes)
4528 dynamic objects allocated (127500 bytes)
1 garbage collections (0 bytes collected)
Try this:
import java.io.*; public class Write{ public static void main(String[] args) throws IOException{ BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); System.out.print("Please enter the file name to create : "); String file_name = in.readLine(); File file = new File(file_name); boolean exist = file.createNewFile(); if (!exist){ System.out.println("File already exists."); System.exit(0); } else{ FileWriter fstream = new FileWriter(file_name); BufferedWriter out = new BufferedWriter(fstream); out.write(in.readLine()); out.close(); System.out.println("File created successfully."); } } }
Thanks
<p>Thank you very much, but it did not help me. I am writing software code in the Java Wireless toolbar 2.3 beta. For this purpose, the expansion of the java file open. After I added you provide the program code into the file . Put this file in src directory. I do not think I am correct in this series? what I wrong? .. This should be a help to me</p> <p>Project settings saved</p> <p>Building "India"</p> <p>C:\WTK23\apps\India\src\Write.java:6: cannot resolve symbol symbol : class BufferedReader </p> <p>location: class Write BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); ^ C:\WTK23\apps\India\src\Write.java:6: cannot resolve symbol symbol : class BufferedReader location: class Write BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); ^ C:\WTK23\apps\India\src\Write.java:6: cannot resolve symbol symbol : variable in </p> <p>location: class java.lang.System</p> <p>BufferedReader in = new BufferedReader(new </p> <p>InputStreamReader(System.in)); ^ C:\WTK23\apps\India\src\Write.java:9: cannot resolve symbol symbol : class File location: class Write File file = new File(file_name); ^ C:\WTK23\apps\India\src\Write.java:9: cannot resolve symbol symbol : class File </p> <p>location: class Write</p> <p>File file = new File(file_name);</p> <pre class="prettyprint"> ^ </code></pre> <p>C:\WTK23\apps\India\src\Write.java:16: cannot resolve symbol symbol : class FileWriter </p> <p>location: class Write FileWriter fstream = new FileWriter(file_name);</p> <p> ^ C:\WTK23\apps\India\src\Write.java:16: cannot resolve symbol symbol : class FileWriter </p> <p>location: class Write FileWriter fstream = new FileWriter(file_name); ^ C:\WTK23\apps\India\src\Write.java:17: cannot resolve symbol symbol : class BufferedWriter location: class Write BufferedWriter out = new BufferedWriter(fstream); ^ C:\WTK23\apps\India\src\Write.java:17: cannot resolve symbol symbol : class BufferedWriter location: class Write</p> <p> BufferedWriter out = new BufferedWriter(fstream); ^ 9 errors com.sun.kvem.ktools.ExecutionException Build failed</p> <p>Running with storage root DefaultColorPhone</p> <p>Running with locale: Russian_Russia.1251</p> <p>Unable to create MIDlet Write java.lang.ClassNotFoundException: Write</p> <pre class="prettyprint">at com.sun.midp.midlet.MIDletState.createMIDlet(+29) at com.sun.midp.midlet.Selector.run(+22) </code></pre> <p>Execution completed.</p> <p>917006 bytecodes executed</p> <p>27 thread switches</p> <p>893 classes in the system (including system classes)</p> <p>4520 dynamic objects allocated (127232 bytes)</p> <p>1 garbage collections (0 bytes collected)</p>
Ads