【发布时间】:2020-09-24 10:00:38
【问题描述】:
我正在使用平台窗口和 Java(用于写入文件)和 C# Unity3D 用于读取内存映射文件。
我将它用于 Java
File f = new File("c:\\tmp\\mapped.txt");
f.delete();
FileChannel fc = new RandomAccessFile(f, "rw").getChannel();
long bufferSize=8*1000;
MappedByteBuffer mem =fc.map(FileChannel.MapMode.READ_WRITE, 0, bufferSize);
int start = 0;
long counter=1;
long startT = System.currentTimeMillis();
long noOfMessage = 1000;
for(;;)
{
if(!mem.hasRemaining())
{
start+=mem.position();
mem =fc.map(FileChannel.MapMode.READ_WRITE, start, bufferSize);
}
mem.putLong(counter);
counter++;
if(counter > noOfMessage )
break;
Thread.sleep(400);
}
对于 C# Unity3D,我正在读取内存中的文件
// Update is called once per frame
void Update()
{
using (MemoryMappedFile mappedFile = MemoryMappedFile.OpenExisting("C:\\tmp\\mapped.txt"))
{
using (var accessor = mappedFile.CreateViewAccessor())
{
accessor.Read(1, out int omegay);
Debug.Log("counter " + omegay.ToString());
}
}
}
当前的问题。
- Java 文件写入文件,文件内有空值,而不是应有的整数。
- 在 C# Unity3D 中出现无法打开文件异常
【问题讨论】: