「java自定义结构」java结构定义语句
本篇文章给大家谈谈java自定义结构,以及java结构定义语句对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。
本文目录一览:
如何在java中定义一个结构体
像C/C++里的,第三方的Javolution库提供了类似的解决方案:
enum Gender{MALE, FEMALE};
struct Date {
unsigned short year;
unsigned byte month;
unsigned byte day;
};
struct Student {
enum Gender gender;
char name[64];
struct Date birth;
float grades[10];
Student* next;
};
public enum Gender { MALE, FEMALE };
public static class Date extends Struct {
public final Unsigned16 year = new Unsigned16();
public final Unsigned8 month = new Unsigned8();
public final Unsigned8 day = new Unsigned8();
}
public static class Student extends Struct {
public final Enum32Gender gender = new Enum32Gender(Gender.values());
public final UTF8String name = new UTF8String(64);
public final Date birth = inner(new Date());
public final Float32[] grades = array(new Float32[10]);
public final Reference32Student next = new Reference32Student();
}
Java如何自定义的树结构? 不要菜单形式的,要如果二叉树那样的
就是类嘛,
不管这个怎么展示,看一个节点是什么,
/*
* 节点
* 一个节点应保存当前节点属性和父节点的引用
*/
public class TreeNode1{
String name; // 节点名
String pName; // 父节点名
}
/*
* 节点
* 一个节点应保存当前节点属性和父节点的引用
*/
public class TreeNode2{
int floor; // 层次
String name; // 节点名
int pFloor; // 父节点层次
}
/*
* 节点
* 一个节点应保存当前节点属性和父节点的引用
*/
public class TreeNode3{
String name; // 节点名
TreeNode3 pNode; // 父节点
}
java自定义数据结构碰到了问题,望高手指点
Java代码
public static void message(){
// String package_header_signature = "hello";
// int file_num=8;
//
// for(int i=0;i8;i++){
// int file_path_length="";
int file_size ="";
// String file_path="";
// }
// 只列了简单几个,原因都懂的!
// }
public static void test(String src,String target) throws Exception{
File file =new File(src);
//String target = "g://test.pkg";
File targetFile = new File(target);
if(!targetFile.exists()){
targetFile.createNewFile();
}
OutputStream os = new FileOutputStream(targetFile);
//write some message
String package_header_signature = "hello";
addByte(package_header_signature.getBytes(), os, 4);
//文件个数
int filesum=0;
//文件路径
ListString strList = new ArrayListString();
filesum =listFlieSum(file,strList);
//加入文件个数
addByte(intToByte(filesum,1),os, 1);
for(int i=0;istrList.size();i++){
File fileInfo = new File(strList.get(i));
String file_path = fileInfo.getAbsolutePath();
int file_path_length = file_path.length();
int file_size = getFileSize(fileInfo);
//加入文件路径长度
addByte(intToByte(file_path_length,1), os, 1);//文件路径的长度
//加入文件大小
addByte(intToByte(file_size,4), os, 4);//文件大小
//加入文件路径
addByte(file_path.getBytes(), os, file_path.length());//文件路径
}
listFile(file,os);
String crc32 = getFileCRCCode(targetFile);
byte[] crcbyte = crc32.getBytes();
os.close();
/**
* int to byte[] 支持 1或者 4 个字节
* @param i
* @param len
* @return
*/
public static byte[] intToByte(int i,int len) {
byte[] abyte=null;
if(len==1){
abyte = new byte[len];
abyte[0] = (byte) (0xff i);
}else{
abyte = new byte[len];
abyte[0] = (byte) (0xff i);
abyte[1] = (byte) ((0xff00 i) 8);
abyte[2] = (byte) ((0xff0000 i) 16);
abyte[3] = (byte) ((0xff000000 i) 24);
}
return abyte;
}
public static int bytesToInt(byte[] bytes) {
int addr=0;
if(bytes.length==1){
addr = bytes[0] 0xFF;
}else{
addr = bytes[0] 0xFF;
addr |= ((bytes[1] 8) 0xFF00);
addr |= ((bytes[2] 16) 0xFF0000);
addr |= ((bytes[3] 24) 0xFF000000);
}
return addr;
}
关于java自定义结构和java结构定义语句的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。
发布于:2022-12-21,除非注明,否则均为
原创文章,转载请注明出处。