createfile

File.createTempFile in Java getting Incompatible type error

南楼画角 提交于 2020-06-29 03:51:08
问题 Till now my code works fine where I am creating file in temporary directory and processing it. But now I am trying to provide specific directory where I actually want to create xml file. So in method createTmpXmlFile private static Path createTmpXmlFile(final String prefix) { try { log.info("Creating temporary file {}{}", prefix, XML_SUFFIX); return Files.createTempFile(Paths.get(gleifZipFile), prefix, XML_SUFFIX); } catch (IOException e) { throw new IllegalStateException("Could not create

Create a file if it doesn't exist

时光毁灭记忆、已成空白 提交于 2020-04-05 07:15:47
问题 I'm trying to open a file, and if the file doesn't exist, I need to create it and open it for writing. I have this so far: #open file for reading fn = input("Enter file to open: ") fh = open(fn,'r') # if file does not exist, create it if (!fh) fh = open ( fh, "w") The error message says there's an issue on the line if(!fh) . Can I use exist like in Perl? 回答1: If you don't need atomicity you can use os module: import os if not os.path.exists('/tmp/test'): os.mknod('/tmp/test') UPDATE : As Cory

Create a file if it doesn't exist

泪湿孤枕 提交于 2020-04-05 07:14:09
问题 I'm trying to open a file, and if the file doesn't exist, I need to create it and open it for writing. I have this so far: #open file for reading fn = input("Enter file to open: ") fh = open(fn,'r') # if file does not exist, create it if (!fh) fh = open ( fh, "w") The error message says there's an issue on the line if(!fh) . Can I use exist like in Perl? 回答1: If you don't need atomicity you can use os module: import os if not os.path.exists('/tmp/test'): os.mknod('/tmp/test') UPDATE : As Cory

createFile() and DeviceIoControl() equivalent for volume devices in Unix/Linux

好久不见. 提交于 2020-03-04 21:26:21
问题 I have opened volume USB device and locked using CreateFile() and DeviceIoControl() in Windows. I want same functionality on Linux/Unix system. I am new to Unix So How to get it? My code for Windows : HANDLE handle = CreateFile(L"\\\\.\\F:", // F: drive to open GENERIC_READ, // no access to the drive FILE_SHARE_READ, // share mode NULL, // default security attributes OPEN_EXISTING, // disposition 0x1, // file attributes NULL); // do not copy file attributes DWORD lpBytesReturned; if

Windows进程的内核对象句柄表

有些话、适合烂在心里 提交于 2020-02-24 05:54:45
当一个进程被初始化时,系统要为它分配一个句柄表。该句柄表只用于内核对象 ,不用于用户对象或GDI对象。 创建内核对象 当进程初次被初始化时,它的句柄表是空的。然后,当进程中的线程调用创建内核对象的函数时,比如CreateFileMapping,内核就为该对象分配一个内存块,并对它初始化。这时,内核对进程的句柄表进行扫描,找出一个空项。由于表 3 - 1中的句柄表是空的,内核便找到索引1位置上的结构并对它进行初始化。该指针成员将被设置为内核对象的数据结构的内存地址,访问屏蔽设置为全部访问权,同时,各个标志也作了设置。 下面列出了用于创建内核对象的一些函数(不是个完整的列表): HANDLE CreateThread( PSECURITY_ATTRIBUTE psa, DWORD dwStackSize, LPTHREAD_START_ROUTINE pfnStartAddr, PVOID pvParam, DWORD dwCreationFlags, PDWORD pdwThreadId); HANDLE CreateFile( PCTSTR pszFileNAme, DWORD dwDesiredAccess, DWORD dwShareMode, PSECURITY_ATTRIBUTES psa, DWORD dwCreationDistribution, DWORD

Create file with command line in Node

孤人 提交于 2020-01-22 13:26:08
问题 So I'm attempting to do this Node.js tutorial, and it says to create three .js files from the command line. touch server.js client.js test.js Except I get the following error: 'touch' is not recognized as an internal or external command, operable program or batch file. Not sure what is wrong here. I've installed Node.js as well as npm and browserify. I've created the package.json file correctly. I suppose I could go into the project directory, right click and make a new file that way, but

SetupComm, SetCommState, SetCommTimeouts fail with USB device

本秂侑毒 提交于 2020-01-15 15:30:35
问题 i am opening a USB device: for communication using CreateFile : HANDLE hUsb = CreateFile("\\.\LCLD9", GENERIC_READ | GENERIC_WRITE, 0, null, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, 0); The call succeeds (i.e. hUsb is not equal to INVALID_HANDLE_VALUE). But then it comes time to do what we do with every serial port: SetupComm (set receive and transit buffer sizes) SetCommState (set flow-control, baud rate, etc) SetCommTimeouts (set timeouts) Each of these calls with GetLastError code of 1 . E.g.:

SetupComm, SetCommState, SetCommTimeouts fail with USB device

泄露秘密 提交于 2020-01-15 15:30:08
问题 i am opening a USB device: for communication using CreateFile : HANDLE hUsb = CreateFile("\\.\LCLD9", GENERIC_READ | GENERIC_WRITE, 0, null, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, 0); The call succeeds (i.e. hUsb is not equal to INVALID_HANDLE_VALUE). But then it comes time to do what we do with every serial port: SetupComm (set receive and transit buffer sizes) SetCommState (set flow-control, baud rate, etc) SetCommTimeouts (set timeouts) Each of these calls with GetLastError code of 1 . E.g.:

visual studio 下 C++生成dump文件

梦想与她 提交于 2020-01-08 20:26:48
1 lib配置 项目-->属性-->配置属性-->链接器-->输入-->附加依赖项 增加dbghelp.lib 2 头文件 #include <imagehlp.h> #include <Windows.h> 3 main函数 在第一行调用window api:SetUnhandledExceptionFilter(UnhandledExceptionFilter2); 4 UnhandledExceptionFilter2的实现 LONG WINAPI UnhandledExceptionFilter2(struct _EXCEPTION_POINTERS* ExceptionInfo) { string strDumpFile = "exception.dmp "; HANDLE hFile = CreateFile(strDumpFile.c_str(), GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL, NULL ); if (hFile!=INVALID_HANDLE_VALUE) { MINIDUMP_EXCEPTION_INFORMATION ExInfo; ExInfo.ThreadId = ::GetCurrentThreadId(); ExInfo

Visual Basic: Checking if file exists, if not, create the file

心不动则不痛 提交于 2020-01-06 14:17:38
问题 This is the code. It checks if the file in path exists, if not, it creates the file. I'm getting this error message all the time and I don't know why. Maybe I should close the System.IO.Directory.Exists? If yes, how do I do that? Just so you know, I'm creating a text file. The code If Not (System.IO.Directory.Exists(path)) Then Dim fs3 As FileStream = File.Create(path) End If This is the error message I get: Process can't use the file (path) because some other process is using this file at