Since i am yet to find any append commands in Java,i have decided to do something that would do the same job.
CODE
import java.io.*;
class col {
public void ncd(){
try {
FileReader trdr=new FileReader("C:/col.txt");
BufferedReader brdr=new BufferedReader(trdr);
int x=0;
String[] ptxt=new String[1000];
String word;
while ((word=brdr.readLine())!=null) {
x++;
ptxt[x]=word;
}
brdr.close();
trdr.close();
FileWriter twrt=new FileWriter("C:/col.txt");
BufferedWriter bwrt=new BufferedWriter(twrt);
for (int i=0;i<x;i++){
bwrt.write(ptxt[i]);
bwrt.newLine();
}
bwrt.write("Ha");
bwrt.close();
twrt.close();
}
catch (IOException e) {
System.out.println(e.getMessage());
}
}
}
public class Main {
public static void main(String[] args) {
col a=new col();
a.ncd();
}
}
The Problem is that when i run the program it says
Exception in thread "main" java.lang.NullPointerException
at java.io.Writer.write(Unknown Source)
at col.ncd(Main.java:20)
at Main.main(Main.java:78)
any ideas of what the problem is ?
P.S i haven't written a void that is in my program but i don't think i need it