Questions tagged [file]

A block of arbitrary information, or resource for storing information, accessible by the string-based name or path. Files are available to computer programs and are usually based on some kind of persistent storage.

A computer file is a block of arbitrary information, or resource for storing information, which is available to a computer program and is usually based on some kind of durable storage. A file is durable in the sense that it remains available for programs to use after the current program has finished. Computer files can be considered as the modern counterpart of paper documents which traditionally are kept in offices' and libraries' files, and this is the source of the term.

In modern computer architectures, files are organized in a tree structure. On the top, you have a root like C:\ in systems. There are several subfolders (inner nodes) below the root, e.g. Program Files or Users. The computer files, which contain the data, are the leaves of that tree.

On based systems, many types of system information are also represented as files, in filesystems such as sysfs and devfs, even though they don't represent information on a durable storage medium.


References


Related

, , , , ,

81192 questions
461
votes
8 answers

How can I get a file's size in C?

How can I find out the size of a file I opened with an application written in C? I would like to know the size because I want to put the content of the loaded file into a string, which I allocate using malloc(). Just writing…
Nino
  • 5,261
  • 4
  • 22
  • 15
455
votes
14 answers

Easiest way to read from and write to files

There are a lot of different ways to read and write files (text files, not binary) in C#. I just need something that is easy and uses the least amount of code, because I am going to be working with files a lot in my project. I only need something…
ApprenticeHacker
  • 21,351
  • 27
  • 103
  • 153
454
votes
3 answers

Getting the filenames of all files in a folder

I need to create a list with all names of the files in a folder. For example, if I have: 000.jpg 012.jpg 013.jpg I want to store them in a ArrayList with [000,012,013] as values. What's the best way to do it in Java ? PS: I'm on Mac OS X
user680406
  • 5,637
  • 6
  • 24
  • 19
452
votes
15 answers

Downloading a file from spring controllers

I have a requirement where I need to download a PDF from the website. The PDF needs to be generated within the code, which I thought would be a combination of freemarker and a PDF generation framework like iText. Any better way? However, my main…
MilindaD
  • 7,533
  • 9
  • 43
  • 63
449
votes
16 answers

How to test if string exists in file with Bash?

I have a file that contains directory names: my_list.txt : /tmp /var/tmp I'd like to check in Bash before I'll add a directory name if that name already exists in the file.
Toren
  • 6,648
  • 12
  • 41
  • 62
448
votes
7 answers

Download a file from NodeJS Server using Express

How can I download a file that is in my server to my machine accessing a page in a nodeJS server? I'm using the ExpressJS and I've been trying this: app.get('/download', function(req, res){ var file = fs.readFileSync(__dirname +…
439
votes
12 answers

Changing Vim indentation behavior by file type

Could someone explain to me in simple terms the easiest way to change the indentation behavior of Vim based on the file type? For instance, if I open a Python file it should indent with 2 spaces, but if I open a Powershell script it should use 4…
EBGreen
  • 36,735
  • 12
  • 65
  • 85
430
votes
19 answers

Get names of all files from a folder with Ruby

I want to get all file names from a folder using Ruby.
Željko Filipin
  • 56,372
  • 28
  • 94
  • 125
430
votes
16 answers

Standard concise way to copy a file in Java?

It has always bothered me that the only way to copy a file in Java involves opening streams, declaring a buffer, reading in one file, looping through it, and writing it out to the other steam. The web is littered with similar, yet still slightly…
Peter
  • 29,498
  • 21
  • 89
  • 122
427
votes
4 answers

How to remove files and directories quickly via terminal (bash shell)

From a terminal window: When I use the rm command it can only remove files. When I use the rmdir command it only removes empty folders. If I have a directory nested with files and folders within folders with files and so on, is there a way to…
None
418
votes
19 answers

How can I find encoding of a file via a script on Linux?

I need to find the encoding of all files that are placed in a directory. Is there a way to find the encoding used? The file command is not able to do this. The encoding of interest to me is ISO 8859-1. If the encoding is anything else, I want to…
Manglu
  • 10,744
  • 12
  • 44
  • 57
414
votes
18 answers

How to create a temporary directory/folder in Java?

Is there a standard and reliable way of creating a temporary directory inside a Java application? There's an entry in Java's issue database, which has a bit of code in the comments, but I wonder if there is a standard solution to be found in one of…
Peter Becker
  • 8,795
  • 7
  • 41
  • 64
410
votes
28 answers

How do I watch a file for changes?

I have a log file being written by another process which I want to watch for changes. Each time a change occurs I'd like to read the new data in to do some processing on it. What's the best way to do this? I was hoping there'd be some sort of hook…
Jon Cage
  • 36,366
  • 38
  • 137
  • 215
401
votes
12 answers

byte[] to file in Java

With Java: I have a byte[] that represents a file. How do I write this to a file (ie. C:\myfile.pdf) I know it's done with InputStream, but I can't seem to work it out.
elcool
  • 6,041
  • 7
  • 29
  • 44
401
votes
11 answers

How to check whether a file is empty or not

I have a text file. How can I check whether it's empty or not?
webminal.org
  • 44,948
  • 37
  • 94
  • 125