public static void deleteServer(int index) throws IOException {
BufferedReader reader = null;
PrintWriter writer = null;
try {
File file = new File(getFilePath());
String fileToWrite = "fileToWrite.txt";
reader = new BufferedReader(new FileReader(file));
writer = new PrintWriter(new FileWriter(fileToWrite));
int current = 0;
String line;
while ((line = reader.readLine()) != null) {
if (current != index) {
writer.println(line);
}
current++;
}
} catch (IOException e) {
e.printStackTrace();
} finally {
if (writer != null) {
writer.close();
}
if (reader != null) {
reader.close();
}
}
}
Thread t = new Thread(new Runnable() {
@Override
public void run() {
parse();
}
});
t.start();
/* fscanf example */
#include <stdio.h>
int main ()
{
char str [80];
float f;
FILE * pFile;
pFile = fopen ("myfile.txt","w+");
fprintf (pFile, "%f %s", 3.1416, "Hello");
rewind (pFile);
fscanf (pFile, "%f", &f);
fscanf (pFile, "%s", str);
fclose (pFile);
printf ("I have read: %f and %s \n",f,str);
return 0;
}
I have read: 3.141600 and Hello