반응형
메모장이 모두를 능가합니까?
Windows Server 2012 R2 시스템에서 Kotlin 프로그램은 FileChannel.tryLock()
다음과 같이 파일에 대한 독점 잠금을 보유합니다.
val fileRw = RandomAccessFile(file, "rw")
fileRw.channel.tryLock()
이 잠금이 설정 되면 다음으로 파일을 열 수 없습니다 .
- 워드 패드
- 메모장 ++
프로그래밍 C #과,의 값
FileShare
:using (var fileStream = new FileStream(processIdPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) using (var textReader = new StreamReader(fileStream)) { textReader.ReadToEnd(); }
명령 행에서 다음
type
명령을 수행하십시오.C:\some-directory>type file.txt The process cannot access the file because another process has locked a portion of the file.
Internet Explorer (예, 필사적이었습니다)
내가 할 수 메모장에서 엽니 다.
도대체 메모장이 다른 방법으로는 할 수없는 잠긴 파일을 어떻게 열 수 있습니까?
메모장은 시도한 다른 편집기에서 사용되는 "일반적인"파일 읽기 메커니즘을 사용하지 않고 먼저 파일을 메모리에 매핑하여 파일을 읽습니다. 이 방법을 사용하면 독점 범위 기반 잠금 기능이 있더라도 파일을 읽을 수 있습니다.
C #에서 다음과 같은 내용을 사용하여 동일한 결과를 얻을 수 있습니다.
using (var f = new FileStream(processIdPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
using (var m = MemoryMappedFile.CreateFromFile(f, null, 0, MemoryMappedFileAccess.Read, null, HandleInheritability.None, true))
using (var s = m.CreateViewStream(0, 0, MemoryMappedFileAccess.Read))
using (var r = new StreamReader(s))
{
var l = r.ReadToEnd();
Console.WriteLine(l);
}
참고 URL : https://stackoverflow.com/questions/45644934/notepad-beats-them-all
반응형
'Programing' 카테고리의 다른 글
콘솔에 유니 코드 문자를 쓰는 방법? (0) | 2020.07.01 |
---|---|
Firefox 웹 콘솔이 비활성화 되었습니까? (0) | 2020.07.01 |
면도기에서 "Html.BeginForm"을 작성하는 방법 (0) | 2020.07.01 |
AppDomain이란 무엇입니까? (0) | 2020.07.01 |
IIS8의 IIS_IUSRS 및 IUSR 권한 (0) | 2020.07.01 |