我有一个问题与ShortBuffer。这是我的代码:
FileChannel fc = new FileInputStream("C:/Dane DMS/"+names2).getChannel();
ByteBuffer bb = ByteBuffer.allocateDirect((int) fc.size());
while (bb.remaining() > 0) fc.read(bb);
fc.close();
bb.flip();
// choose the right endianness
ShortBuffer sb = bb.order(ByteOrder.BIG_ENDIAN).asShortBuffer();
在这个文件中我有一个矩阵。
111 222 333 123
444 555 666 456
777 888 999 789
098 765 432 321
我需要把这个矩阵改成:
098 765 432 321
777 888 999 789
444 555 666 456
111 222 333 123
我必须改变这个矩阵或创建从数字098开始到数字123结束的循环。
I不打印这个矩阵。我使用:
for(int i = 0; i<=1200; i++)
{
for(int j = 0; j<=1200 ; j++)
{
}
}
到交叉矩阵,但这样我从111开始,我需要从098开始,到123结束。
你可以试试这个
FileChannel fc = new FileInputStream("C:/Dane DMS/"+names2).getChannel();
ByteBuffer bb = ByteBuffer.allocateDirect((int) fc.size());
while (bb.remaining() > 0) fc.read(bb);
fc.close();
bb.flip();
// choose the right endianness
ShortBuffer sb = bb.order(ByteOrder.BIG_ENDIAN).asShortBuffer();
short[][] Matrix = new short[1201][1201];
for(int i = 0; i<=1200; i++)
{
for(int j = 0; j<=1200 ; j++)
{
Matrix[1200-i][j] = sb.get(i*1201+j);
}
}
所以你需要反转行?要做到这一点,需要计算出行长度。然后你可以交换第一行和最后一行,然后是第二行最后一行和第二行等等。