Results 1 to 4 of 4
Thread: Problem here!
- 03-26-2011, 02:37 PM #1
Member
- Join Date
- Mar 2011
- Posts
- 4
- Rep Power
- 0
Problem here!
What's wrong in this code the first time i run this it's OK but when i closed the notepad and rerun the program there's an error occured:
PHP Code:import java.io.*; public class WriteFile{ public static void main(String[] args) throws IOException{ BufferedReader input = new BufferedReader(new InputStreamReader(System.in)); File f=new File("textfile1.txt"); FileOutputStream fop=new FileOutputStream(f); System.out.print("Enter test: "); String test1 = input.readLine(); System.out.print("Enter test"); String test2 = input.readLine(); System.out.print("Enter test:"); String test3 = input.readLine(); System.out.print("Enter test:"); String test4 = input.readLine(); System.out.print("Enter test:"); String test5 = input.readLine(); System.out.print("Enter test:"); String test6 = input.readLine(); System.out.print("Enter test:"); String test7 = input.readLine(); System.out.print("Enter test:"); String test8 = input.readLine(); System.out.print("Enter test:"); if(f.exists()){ String str= test1; String str2= test2; String str3= test3; String str4= test4; String str5= test5; String str6= test6; String str7= test7; String str8= test8; fop.write(str.getBytes()); fop.write(str2.getBytes()); fop.write(str3.getBytes()); fop.write(str4.getBytes()); fop.write(str5.getBytes()); fop.write(str6.getBytes()); fop.write(str7.getBytes()); fop.write(str8.getBytes()); fop.flush(); fop.close(); System.out.println("The data has been written"); } else System.out.println("This file is not exist"); } }Last edited by Fubarable; 03-26-2011 at 02:56 PM. Reason: code tags added
- 03-26-2011, 02:44 PM #2
Member
- Join Date
- Mar 2011
- Posts
- 4
- Rep Power
- 0
here's the snapshot of the error:
Last edited by newbieph; 03-26-2011 at 02:47 PM.
- 03-26-2011, 03:17 PM #3
Member
- Join Date
- Mar 2011
- Posts
- 7
- Rep Power
- 0
try this
File f=new File(C:\..\..\file.txt)
PrintStream prinstr=new PrintStream(f);
Scanner sc=new Scanner(System.in);
String input=sc.nextLine();
if (f.exists()) ....
printstr.println(input);
printstr.close;
I think problem is to file path
must C:\..\..\file.txt - use \\ for \
- 03-26-2011, 03:52 PM #4
Not at all. Did you look at the error messages at all?I think problem is to file path
@ newbieph:
1. Don't post images that end up all blurry, copy and paste the contents of the command prompt.
2. Update your Java version, 1.4.2 was EOLed a long time ago.
3. Get rid of your own class named File, or otherwise disambiguate between that and java.io.File.
4. Go through Code Conventions for the Java(TM) Programming Language: Contents and learn how to indent code correctly.
5. Why do you have a whole set of duplicate references to the same Strings?
db


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks