【急】Java代码,调试出现(Unknown Source)问题,会是什么原因?

【急】Java代码,调试出现(Unknown Source)问题,会是什么原因?,第1张

Unknown Source就是未知的源文件

原因是:class文件中陪镇没有源文件的相关调试信息。在基乱指用javac命令进行编译的时候没有指定调试信息。Java中的动态代理类的接口参数的类型不是一个普通的数组,而是类型为Class<?>[] interfaces,这里参考JDK文档中java.lang.reflect.Proxy。

解决搏配方法:

在不确定时,先做判断,判断msg中是否含有“:”,然后使用substring(int arg0)。

String msg = fromServer.readUTF()

int m1 = 0

String msgnew= new String()

if(msg.contains( ":")){

m1 = msg.indexOf( ":")

msgnew = new String(msg.substring(m1))

}

能不能换个思路~~~汗啊~!好像用java的函毁帆数只能穗让取得lastModified()有一个比较笨的方法

Process p=Runtime.getRuntime().exec("dir startup.bat /t -c")

然后取得p的输出信息就可以得到纤族雹创建时间了!上面的例子我是得到tomcat的startup.bat这个文件的创建时间,如果你想得到其它文件的创建时间就可以将startup.bat换成其它文件名!study and mark ^_^如果用dir, 取得创建时间的参数是/TC路过学习ing帮您顶java是用native来获取 *** 作系统的支持,从而对文件进行 *** 作。

具体实现类是

java.io.FileSystem

这个类是私有的只能在jdk内部使用,由于这个类没有提供文件时间创建的接口,你也就没有办法用纯java来获得这一个功能(但愿不是这样)。

有一个简单的方法是自己调用系统函数,或者干脆调用各C函数

先写各本地类访问方法

class MyFileSystem{

public native void getCreatFileTime(File f)static {System.loadLibrary(" ")}

public static void main(String[] args) {

new HelloWorld().getCreatFileTime()}}编译本文件然后执行 javah,便会自动产生头文件 MyFileSystem.h

函数的具体实现如下:

#include

#include "MyFileSystem.h"

#include

JNIEXPORT double JNICALL

Java_MyFileSystem_displayHelloWorld(JNIEnv *env, jobject obj){//在这里调用C函数

double time=getFileCreatTime_IN_C(obj)

return time}高手如云,我心忐忑

奋发图强~高手如云,我心忐忑奋发图强~me too,高手如云,我心忐忑奋发图强~me too,too还有可以复制java.io.FileSystem及相关类的源代码,把所有东西成public的,这样总可以用了吧,

当然把类名也改掉。。。。。顶!

Study!Up!!!顶一下!

支持upFile f = new File("d:\\a.txt")

Date date = new Date()

long L = date.getTime()

f.setLastModified(L)

以上个函数可以设置文件的最后修改时间,以及设置文件为“只读”属性顶!!!

DES 密钥生成,加解密方法,,你可以看一下

//DES 密钥生成工具

import java.io.File

import java.io.FileNotFoundException

import java.io.FileOutputStream

import java.io.IOException

import java.io.ObjectOutputStream

import java.security.InvalidKeyException

import java.security.NoSuchAlgorithmException

import java.security.SecureRandom

import java.security.spec.InvalidKeySpecException

import javax.crypto.KeyGenerator

import javax.crypto.SecretKey

import javax.crypto.SecretKeyFactory

import javax.crypto.spec.DESKeySpec

public class GenKey {

private static final String DES = "DES"

public static final String SKEY_NAME = "key.des"

public static void genKey1(String path) {

// 密钥

SecretKey skey = null

// 密钥随机数生成

SecureRandom sr = new SecureRandom()

//生成密钥文件

File file = genFile(path)

try {

// 获取密钥生成实例

KeyGenerator gen = KeyGenerator.getInstance(DES)

/知拆链/ 初始化密钥生成器

gen.init(sr)

// 生成密钥

skey = gen.generateKey()

// System.out.println(skey)

ObjectOutputStream oos = new ObjectOutputStream(

new FileOutputStream(file))

oos.writeObject(skey)

oos.close()

} catch (NoSuchAlgorithmException e) {

e.printStackTrace()

} catch (FileNotFoundException e) {

e.printStackTrace()

} catch (IOException e) {

e.printStackTrace()

}

}

/**

* @param file : 生成密钥的御升路径

* SecretKeyFactory 方式生成des密钥

* */

public static void genKey2(String path) {

// 密搭孙钥随机数生成

SecureRandom sr = new SecureRandom()

// byte[] bytes = {11,12,44,99,76,45,1,8}

byte[] bytes = sr.generateSeed(20)

// 密钥

SecretKey skey = null

//生成密钥文件路径

File file = genFile(path)

try {

//创建deskeyspec对象

DESKeySpec desKeySpec = new DESKeySpec(bytes,9)

//实例化des密钥工厂

SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(DES)

//生成密钥对象

skey = keyFactory.generateSecret(desKeySpec)

//写出密钥对象

ObjectOutputStream oos = new ObjectOutputStream(

new FileOutputStream(file))

oos.writeObject(skey)

oos.close()

} catch (NoSuchAlgorithmException e) {

e.printStackTrace()

} catch (InvalidKeyException e) {

e.printStackTrace()

} catch (InvalidKeySpecException e) {

e.printStackTrace()

} catch (FileNotFoundException e) {

e.printStackTrace()

} catch (IOException e) {

e.printStackTrace()

}

}

private static File genFile(String path) {

String temp = null

File newFile = null

if (path.endsWith("/") || path.endsWith("\\")) {

temp = path

} else {

temp = path + "/"

}

File pathFile = new File(temp)

if (!pathFile.exists())

pathFile.mkdirs()

newFile = new File(temp+SKEY_NAME)

return newFile

}

/**

* @param args

*/

public static void main(String[] args) {

// TODO Auto-generated method stub

genKey2("E:/a/aa/")

}

}

//DES加解密方法

import java.io.BufferedInputStream

import java.io.BufferedOutputStream

import java.io.File

import java.io.FileInputStream

import java.io.FileNotFoundException

import java.io.FileOutputStream

import java.io.ObjectInputStream

import javax.crypto.Cipher

import javax.crypto.CipherInputStream

import javax.crypto.SecretKey

import org.apache.commons.logging.Log

import org.apache.commons.logging.LogFactory

/**

*制卡文件加/解密 加密方式DES

*/

public class SecUtil {

public static final Log log = LogFactory.getLog(SecUtil.class)

/**

* 解密

*

* @param keyPath

*密钥路径

* @param source

*解密前文件

* @param dest

*解密后文件

*/

public static void decrypt(String keyPath, String source, String dest) {

SecretKey key = null

try {

ObjectInputStream keyFile = new ObjectInputStream(

// 读取加密密钥

new FileInputStream(keyPath))

key = (SecretKey) keyFile.readObject()

keyFile.close()

} catch (FileNotFoundException ey1) {

log.info("Error when read keyFile")

throw new RuntimeException(ey1)

} catch (Exception ey2) {

log.info("error when read the keyFile")

throw new RuntimeException(ey2)

}

// 用key产生Cipher

Cipher cipher = null

try {

// 设置算法,应该与加密时的设置一样

cipher = Cipher.getInstance("DES")

// 设置解密模式

cipher.init(Cipher.DECRYPT_MODE, key)

} catch (Exception ey3) {

log.info("Error when create the cipher")

throw new RuntimeException(ey3)

}

// 取得要解密的文件并解密

File file = new File(source)

String filename = file.getName()

try {

// 输出流,请注意文件名称的获取

BufferedOutputStream out = new BufferedOutputStream(

new FileOutputStream(dest))

// 输入流

CipherInputStream in = new CipherInputStream(

new BufferedInputStream(new FileInputStream(file)), cipher)

int thebyte = 0

while ((thebyte = in.read()) != -1) {

out.write(thebyte)

}

in.close()

out.close()

} catch (Exception ey5) {

log.info("Error when encrypt the file")

throw new RuntimeException(ey5)

}

}

/**

* 加密

* @param keyPath 密钥路径

* @param source 加密前文件

* @param dest 加密后文件

*/

public static void encrypt(String keyPath, String source, String dest) {

SecretKey key = null

try {

ObjectInputStream keyFile = new ObjectInputStream(

// 读取加密密钥

new FileInputStream(keyPath))

key = (SecretKey) keyFile.readObject()

keyFile.close()

} catch (FileNotFoundException ey1) {

log.info("Error when read keyFile")

throw new RuntimeException(ey1)

} catch (Exception ey2) {

log.info("error when read the keyFile")

throw new RuntimeException(ey2)

}

// 用key产生Cipher

Cipher cipher = null

try {

// 设置算法,应该与加密时的设置一样

cipher = Cipher.getInstance("DES")

// 设置解密模式

cipher.init(Cipher.ENCRYPT_MODE, key)

} catch (Exception ey3) {

log.info("Error when create the cipher")

throw new RuntimeException(ey3)

}

// 取得要解密的文件并解密

File file = new File(source)

String filename = file.getName()

try {

// 输出流,请注意文件名称的获取

BufferedOutputStream out = new BufferedOutputStream(

new FileOutputStream(dest))

// 输入流

CipherInputStream in = new CipherInputStream(

new BufferedInputStream(new FileInputStream(file)), cipher)

int thebyte = 0

while ((thebyte = in.read()) != -1) {

out.write(thebyte)

}

in.close()

out.close()

} catch (Exception ey5) {

log.info("Error when encrypt the file")

throw new RuntimeException(ey5)

}

}

}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/tougao/12125331.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-21
下一篇 2023-05-21

发表评论

登录后才能评论

评论列表(0条)

保存