file-io

How to delete a folder with files using Java

风格不统一 提交于 2020-01-18 13:18:09
问题 I want to create and delete a directory using Java, but it isn't working. File index = new File("/home/Work/Indexer1"); if (!index.exists()) { index.mkdir(); } else { index.delete(); if (!index.exists()) { index.mkdir(); } } 回答1: Java isn't able to delete folders with data in it. You have to delete all files before deleting the folder. Use something like: String[]entries = index.list(); for(String s: entries){ File currentFile = new File(index.getPath(),s); currentFile.delete(); } Then you

How to delete a folder with files using Java

社会主义新天地 提交于 2020-01-18 13:16:38
问题 I want to create and delete a directory using Java, but it isn't working. File index = new File("/home/Work/Indexer1"); if (!index.exists()) { index.mkdir(); } else { index.delete(); if (!index.exists()) { index.mkdir(); } } 回答1: Java isn't able to delete folders with data in it. You have to delete all files before deleting the folder. Use something like: String[]entries = index.list(); for(String s: entries){ File currentFile = new File(index.getPath(),s); currentFile.delete(); } Then you

Reset buffer with BufferedReader in Java?

三世轮回 提交于 2020-01-18 04:44:10
问题 I am using class BufferedReader to read line by line in the buffer. When reading the last line in the buffer, I want to start reading from the beginning of the buffer again. I have read about the mark() and reset() , I am not sure its usage but I don't think they can help me out of this. Does anyone know how to start reading from the beginning of the buffer after reaching the last line? Like we can use seek(0) of the RandomAccessFile ? 回答1: mark/reset is what you want, however you can't

Does php file() require fclose() at the end?

我是研究僧i 提交于 2020-01-17 08:44:19
问题 Does PHP automatically close the file after a file(); function, or does it require fclose(); or similar? 回答1: Does PHP automatically close the file after a file(); function, or does it require fclose(); or similar? No, file() doesn't require a fclose() call. You can see that in the source code of the function that it all ends nice and clean, so you don't have to call fclose() or do anything similar, you simple can call file() . Source code: /* {{{ proto array file(string filename [, int flags

Overwriting a document file

寵の児 提交于 2020-01-17 08:07:18
问题 I'm developing a document based desktop app which writes a fairly large and complex file to disk when the user saves his document. What is the best practice to do here to prevent data corruption? There are a number of things that can happen: The save process may fail half way, which is of course a serious application error, but in this case one would rather have the old file left than the corrupted half-written file. The same problem will occur if the application is terminated for some other

Dynamically loading large data in jTable using SwingWorker

给你一囗甜甜゛ 提交于 2020-01-17 07:10:28
问题 In Netbeans, I am trying to create a Desktop Application whose UI looks like below: I am executing "adb logcat command" through Java code which loads 1000s of lines of logs in few seconds & I intend to display all of this information through jTable in NetBeans. Using parameter: adb logcat -t 100 -> I am restricting the logs to 100 lines only right now. However the applet becomes unresponsive (or gets stuck in process() method) for 1000 lines or when removing such restriction on number of

First character in txt file doesn't print in C

…衆ロ難τιáo~ 提交于 2020-01-17 01:14:08
问题 I am a beginner in C. I am making a simple game in c. I have a .txt file that stores players' score such as gse 12 CKY 8 Then I have this function in C and the function prints out score based on .txt file above. int n = 0; int c; int p=0; char name[NAME_LENGTH] = { 0 }; char score[NAME_LENGTH] = { 0 }; FILE *fp = fopen("scoreBoard.txt", "r"); if (fp == NULL) { printf("no score available\n"); fflush(stdin); getchar(); return; } system("cls");//clears the screen if (fp){ while((c=getc(fp)!=EOF)

C++ read from file

前提是你 提交于 2020-01-16 20:57:09
问题 How should I read this file if I know how many int values are after the first value but I don't know how many values are after them. My problem is when I have to read the lines that contains 2 values. Edit: This is my file 5 27 15 42 17 35 20 1 28 2 43 3 Here is what I tried: fin >> n; for (i=1; i<=n; i++) fin >> part[i]; while(!fin.eof()) { nrT++; fin >> tric[nrT][0]; fin >> tric[nrT][1]; } 回答1: for (int a,b; fin >> a >> b; nrT++) { tric[nrT][0] = a; tric[nrT][1] = b; } 回答2: Treat an end of

Read only a part of the file that was written using certain function

孤街浪徒 提交于 2020-01-16 19:49:20
问题 I have a text file for which I use two write functions: 1) Normal Write, 2) Secure Write. Both the write functions take the data and offset in the file to start writing as parameters. Now when I want to read the data from the file, I should be only be able to read the data written using the "Normal Write" function and should not be able to read the data written using "Secure Write" function. When the user attempts to read the data written using the secure write function, then an exception

search in a file for a specific line c code

荒凉一梦 提交于 2020-01-16 09:10:33
问题 I am working on C. I would like to ask what s the best way to search in a file for a specific line (or multiple lines)? Can someone please give me an example. I have 2 files and I would like to see if this two files are 80% identical. I thought about searching in one of the file some specific lines from the other file. Thx I need some example in C code. here is a small example int compareFile(FILE* file_compared, FILE* file_checked) { bool diff = 0; int N = 65536; char* b1 = (char*) calloc (1