在使用eclipse编写java源程序后,该程序保存在内存还是硬盘?

在使用eclipse编写java源程序后,该程序保存在内存还是硬盘?,第1张

在使用 Eclipse 编写 Java 源程序时,程序保存在硬盘上,而不是内存中。当您点击“保存”按钮时,Eclipse 会将程序源代码写入硬盘上的文件。此外,Eclipse 还提供了一些自动保存选项,可以在编写程序时定期保存代码,以防止数据丢失。

一般来讲 要用java得到硬盘空间 有 种方法: 调用system的mand 然后分析得到的结果 这种方法有很强的系统依赖性 linux下和win下要分别写程序下面是一个win下的例子 编译成功之后 运行java Diskspace yourdir(比如c:\)import java io BufferedReaderimport java io InputStreamReader/*** Determine free disk space for a given directory by* parsing the output of the dir mand * This class is inspired by the code at* Works only under Windows under certain circumstances * Yes it s that shaky * Requires Java or higher * @[EMAIL PROTECTED]*Marco Schmidt*/public class Diskspace{private Diskspace(){// prevent instantiation of this class}/*** Return available free disk space for a directory * @[EMAIL PROTECTED]dirName name of the directory* @[EMAIL PROTECTED]free disk space in bytes or if unknown*/public static long getFreeDiskSpace(String dirName){try{// guess correct dir mand by looking at the// operating system nameString os = System getProperty( os name )String mandif (os equals( Windows NT ) ||os equals( Windows )){mand = cmd exe /c dir + dirName}else{mand = /c dir + dirName}// run the dir mand on the argument directory nameRuntime runtime = Runtime getRuntime()Process process = nullprocess = runtime exec(mand)if (process == null){return }// read the output of the dir mand// only the last line is of interestBufferedReader in = new BufferedReader(new InputStreamReader(process getInputStream()))String lineString freeSpace = nullwhile ((line = in readLine()) != null){freeSpace = line}if (freeSpace == null){return }process destroy()// remove dots &mas &leading and trailing whitespacefreeSpace = freeSpace trim()freeSpace = freeSpace replaceAll( \\ )freeSpace = freeSpace replaceAll( )String[] items = freeSpace split( )// the first valid numeric value in items after(!) index // is probably the free disk spaceint index = while (index <items.length){try{long bytes = Long.parseLong(items[index++])return bytes}catch (NumberFormatException nfe){}}return -1}catch (Exception exception){return -1}}/*** Command line program to print the free diskspace to stdout* for all 26 potential root directories A:\ to Z:* (when no parameters are given to this program)* or for those directories (drives) specified as parameters.* @[EMAIL PROTECTED]args program parameters*/public static void main(String[] args){if (args.length == 0){for (char c = 'A'c <= 'Z'c++){String dirName = c + ":\\"System.out.println(dirName + " " +getFreeDiskSpace(dirName))}}else{for (int i = 0i <args.lengthi++){System.out.println(args[i] + " " +getFreeDiskSpace(args[i]))}}}} 方法二:使用Jconfig,可以跨平台 从上下载jconfig.下载的包的sample里有很简单的例子,如果是要得到磁盘空间的话:用FileRegistry.getVolumes()得到DiskVolume然后call getFreeSpace()和getMaxCapacity()就是这么简单..:) 方法三:jni 这个是解决所有和os相关的 *** 作的万能利器了.例子我也懒得写了.写一个dll然后call之即可. lishixinzhi/Article/program/Java/Javascript/201311/25405

有可能硬盘内容多了扩展名。

在硬盘文件里,隐藏已知文件扩展名的选项点开,看看文件是不是多了扩展名,扩展名错误,java是读取不到的。

Java是一门面向对象的编程语言,不仅吸收了C++语言的各种优点,还摒弃了C++里难以理解的多继承、指针等概念,因此Java语言具有功能强大和简单易用两个特征。


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

原文地址: http://outofmemory.cn/yw/7968670.html

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

发表评论

登录后才能评论

评论列表(0条)

保存