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
381
votes
13 answers

Best way to require all files from a directory in ruby?

What's the best way to require all files from a directory in ruby ?
Gaetan Dubar
  • 4,538
  • 2
  • 27
  • 22
381
votes
22 answers

How do I load a file from resource folder?

My project has the following structure: /src/main/java/ /src/main/resources/ /src/test/java/ /src/test/resources/ I have a file in /src/test/resources/test.csv and I want to load the file from a unit test in /src/test/java/MyTest.java I have this…
codereviewanskquestions
  • 13,460
  • 29
  • 98
  • 167
374
votes
9 answers

Save and load MemoryStream to/from a file

I am serializing an structure into a MemoryStream and I want to save and load the serialized structure. So, How to Save a MemoryStream into a file and also load it back from file?
Mahdi Ghiasi
  • 14,873
  • 19
  • 71
  • 119
372
votes
12 answers

How to restore the permissions of files and directories within git if they have been modified?

I have a git checkout. All the file permissions are different than what git thinks they should be therefore they all show up as modified. Without touching the content of the files (just want to modify the permissions) how do I set all the files…
Dale Forester
  • 18,145
  • 10
  • 27
  • 27
368
votes
13 answers

Search and replace a line in a file in Python

I want to loop over the contents of a text file and do a search and replace on some lines and write the result back to the file. I could first load the whole file in memory and then write it back, but that probably is not the best way to do it. What…
pkit
  • 7,993
  • 6
  • 36
  • 36
366
votes
4 answers

How to open a file for both reading and writing?

Is there a way to open a file for both reading and writing? As a workaround, I open the file for writing, close it, then open it again for reading. But is there a way to open a file for both reading and writing?
bigredhat
  • 3,669
  • 2
  • 15
  • 3
364
votes
18 answers

Deleting all files from a folder using PHP?

For example I had a folder called `Temp' and I wanted to delete or flush all files from this folder using PHP. Could I do this?
getaway
  • 8,792
  • 22
  • 64
  • 94
362
votes
17 answers

Nested using statements in C#

I am working on a project. I have to compare the contents of two files and see if they match each other precisely. Before a lot of error-checking and validation, my first draft is: DirectoryInfo di = new DirectoryInfo(Environment.CurrentDirectory…
SBurris
  • 7,378
  • 5
  • 28
  • 36
361
votes
10 answers

How to read/write from/to a file using Go

I've been trying to learn Go on my own, but I've been stumped on trying read from and write to ordinary files. I can get as far as inFile, _ := os.Open(INFILE, 0, 0), but actually getting the content of the file doesn't make sense, because the read…
Seth Hoenig
  • 7,047
  • 6
  • 31
  • 30
351
votes
6 answers

How to read a file in Groovy into a string?

I need to read a file from the file system and load the entire contents into a string in a groovy controller, what's the easiest way to do that?
raffian
  • 31,267
  • 26
  • 103
  • 174
349
votes
9 answers

Fastest way to tell if two files have the same contents in Unix/Linux?

I have a shell script in which I need to check whether two files contain the same data or not. I do this a for a lot of files, and in my script the diff command seems to be the performance bottleneck. Here's the line: diff -q $dst $new >…
JDS
  • 16,388
  • 47
  • 161
  • 224
347
votes
15 answers

Reading a resource file from within jar

I would like to read a resource from within my jar like so: File file; file = new File(getClass().getResource("/file.txt").toURI()); BufferedReader reader = new BufferedReader(new FileReader(file)); //Read the file and it works fine when running…
Koi
  • 3,573
  • 3
  • 13
  • 5
346
votes
22 answers

How to search and replace text in a file

How do I search and replace text in a file using Python 3? Here is my code: import os import sys import fileinput print("Text to search for:") textToSearch = input("> ") print("Text to replace it with:") textToReplace = input("> ") print("File to…
Shriram
  • 4,711
  • 6
  • 20
  • 22
340
votes
9 answers

Create and save a file with JavaScript

I have data that I want to write to a file, and open a file dialog for the user to choose where to save the file. It would be great if it worked in all browsers, but it has to work in Chrome. I want to do this all client-side. Basically I want to…
user1756980
  • 3,807
  • 4
  • 16
  • 13
339
votes
22 answers

How to get the filename without the extension in Java?

Can anyone tell me how to get the filename without the extension? Example: fileNameWithExt = "test.xml"; fileNameWithOutExt = "test";
Iso
  • 3,668
  • 2
  • 20
  • 18