file-io

How to use relative path instead of absolute path?

纵然是瞬间 提交于 2019-12-28 06:24:13
问题 So I am having a strange issue with Java. I'm reading a writing files, so the path is important to me. I would like all files to be written and read from the relative path (i.e in the folder with the rest of my class and java files). I write files like so: FileWriter fw = new FileWriter(outfile,true); fw.write(data); fw.close(); where outfile is something like 'out.txt' (i.e. the name of the file we want the output to go in). The problem is, the file is created in /home/me/ instead of the

Check if a file is open [duplicate]

孤者浪人 提交于 2019-12-28 05:58:30
问题 This question already has answers here : Is there a way to check if a file is in use? (18 answers) Closed 3 years ago . Is there a way to find if a file is already open or not? 回答1: protected virtual bool IsFileinUse(FileInfo file) { FileStream stream = null; try { stream = file.Open(FileMode.Open, FileAccess.ReadWrite, FileShare.None); } catch (IOException) { //the file is unavailable because it is: //still being written to //or being processed by another thread //or does not exist (has

IOError when trying to open existing files

折月煮酒 提交于 2019-12-28 04:35:06
问题 I have a small issue with a python program that I wrote to extract some information from a special text file. The loop (code below) needs to execute my function extract_zcoords() over 500 files (1 file gives one list) so that I can build a dataset. import os def extract_zcoord(filename): f = open(filename, 'r') ... # do something with f ### LOOP OVER DIRECTORY location = '/Users/spyros/Desktop/3NY8MODELSHUMAN/HomologyModels' for filename in os.listdir(location): extract_zcoord(filename) THE

Fill input file form with JavaScript [duplicate]

倖福魔咒の 提交于 2019-12-28 04:30:26
问题 This question already has answers here : How to set file input value when dropping file on page? [duplicate] (1 answer) Dynamically set value of a file input [duplicate] (4 answers) How to set a value to a file input in HTML? (8 answers) Closed 6 years ago . Note: The answer(s) below reflect the state of legacy browsers in 2009. Now you can actually set the value of the file input element dynamically/programatically using JavaScript in 2017. See the answer in this question for details as well

Tried and true simple file copying code in C?

我怕爱的太早我们不能终老 提交于 2019-12-28 04:03:45
问题 This looks like a simple question, but I didn't find anything similar here. Since there is no file copy function in C, we have to implement file copying ourselves, but I don't like reinventing the wheel even for trivial stuff like that, so I'd like to ask the cloud: What code would you recommend for file copying using fopen()/fread()/fwrite()? What code would you recommend for file copying using open()/read()/write()? This code should be portable (windows/mac/linux/bsd/qnx/younameit), stable,

How app can access files on USB OTG storages in Android 6.0 (API level 23) without root?

北战南征 提交于 2019-12-28 04:01:27
问题 Android 6.0 Developer Preview (API level 23) can natively mounts external removable USB OTG storages out-of-the-box without any additional apps (for more info please see: https://www.androidpolice.com/2015/05/28/android-m-feature-spotlight-external-storage-can-be-adopted-as-true-internal-storage-or-accessed-normally-with-no-additional-apps/). When user connects USB OTG storage, it shows up in the system storage menu and it is accessible with the built-in file manager. User can access all

ASP.Net MVC - Read File from HttpPostedFileBase without save

纵饮孤独 提交于 2019-12-28 03:32:06
问题 I am uploading the file by using file upload option. And i am directly send this file from View to Controller in POST method like, [HttpPost] public ActionResult Page2(FormCollection objCollection) { HttpPostedFileBase file = Request.Files[0]; } Assume, i am uploading a notepad file. How do i read this file & append this text to string builder,, without save that file.... I'm aware about after SaveAs this file, we can read this file. But How do i read this file from HttpPostedFileBase without

Write objects into file with Node.js

邮差的信 提交于 2019-12-28 03:29:09
问题 I've searched all over stackoverflow / google for this, but can't seem to figure it out. I'm scraping social media links of a given URL page, and the function returns an object with a list of URLs. When I try to write this data into a different file, it outputs to the file as [object Object] instead of the expected: [ 'https://twitter.com/#!/101Cookbooks', 'http://www.facebook.com/101cookbooks'] as it does when I console.log() the results. This is my sad attempt to read and write a file in

Reading a text file in java

旧巷老猫 提交于 2019-12-28 03:04:26
问题 How would I read a .txt file in Java and put every line in an array when every lines contains integers, strings, and doubles? And every line has different amounts of words/numbers. I'm a complete noob in Java so sorry if this question is a bit stupid. Thanks 回答1: Try the Scanner class which no one knows about but can do almost anything with text. To get a reader for a file, use File file = new File ("...path..."); String encoding = "...."; // Encoding of your file Reader reader = new

Prepend lines to file in Java

蹲街弑〆低调 提交于 2019-12-28 03:04:25
问题 Is there a way to prepend a line to the File in Java, without creating a temporary file, and writing the needed content to it? 回答1: No, there is no way to do that SAFELY in Java. No filesystem implementation in any mainstream operating system supports this kind of thing, and you won't find this feature supported in any mainstream programming languages. Real world file systems are implemented on devices that store data as fixed sized "blocks". It is not possible to implement a file system