Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.
Trending News
important java question?
import java.util.Scanner;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintStream;
class word {
public static void main(String args[])
throws FileNotFoundException {
int loop;
loop = 2;
Scanner written = new Scanner(new File("type.txt"));
Scanner myscanner = new Scanner(System.in);
String karim;
String space;
String reader;
reader = written.nextLine();
space =" ";
System.out.println(reader);
while (loop != 0) {
karim = myscanner.nextLine();
PrintStream diskWriter =
new PrintStream("type.txt");
diskWriter.print(reader+space+karim );
}
}
}
why can't i edit what was written in the file from my program or delete what i wrote
3 Answers
- McFateLv 710 years agoFavorite Answer
Assuming you're asking about the output file that your Java program write (rather than your Java source file itself)... Java's not really good about overwriting portions of files in-place. Not sure why that is.
At one place I work we just made a utility class that can load the entire contents of a file to a list of Strings, and then write the list of Strings to a file. Then you read the file into memory, modify the list of Strings however you want, and write it back out.
- modulo_functionLv 710 years ago
You're probably writing that file using permissions that won't allow an edit or delete.
I think that the problem is the system that you're doing this on.
Can you open the file? Using what program? What operating system?
+add
Ok, I tried your program. You never reset loop. But I was able to get it to take keyboard input and write to the file. I was able to open and see what I wrote.
- ?Lv 410 years ago
The program that you're using (Notepad, or whatever) probably got set to read only maybe? What program are you writing the code in?