首页 \ 问答 \ 获取Java中的绝对路径(Get absolute path in Java)

获取Java中的绝对路径(Get absolute path in Java)

我有字符串:

String s = "~/abc/d.png"

如何获取此文件的绝对路径?

我试过了:

File file = new File(s);
String absolutePath = file.getAbsolutePath();

但它不能重新符号〜符号。


I have string:

String s = "~/abc/d.png"

How can I get absolute path of this file?

I've tried:

File file = new File(s);
String absolutePath = file.getAbsolutePath();

But it can't reslove ~ symbol.


原文:https://stackoverflow.com/questions/12065772
更新时间:2024-01-30 10:01

最满意答案

要回答这个问题,我可以覆盖inline-css吗? ... 是的 ,通过使用!important

你真正的问题:

当屏幕再次变大时,通过向媒体查询添加!important。 请参阅以下代码段(全屏运行并使屏幕更小/更大)

(function(){
  $('button').on('click', function(e){
    $('#test').slideToggle();
  });
})();
		@media screen and (min-width: 1000px) {
			ul {
				height:50px;
				background-color: red;
				width: 100%;
			}
			li {

				display: inline-block;
				height: 50px;
				line-height: 50px;
				float:left;
				margin-left: 50px;
			}
			#test {
				display: block !important;
			}
			button {

				display: none !important;
			}
		}

		@media screen and (max-width: 1000px) {
			ul {
				background-color: red;
				width: 100%;
			}
			li {
				display: block;
				height: 50px;
				line-height: 50px;
			}
			#test {
				display: none;
			}
			button {
				display: block;
			}
		}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="test">
	<ul>
		<li>This</li>
		<li>Is</li>
		<li>a</li>
		<li>menu</li>
	</ul>
</div>
<button >Toggle menu</button>


To answer the question can I override inline-css? ... Yes, by using !important.

Your real question:

By adding !important to your media query when the screen is big again. see following snippet (run in full screen and make screen smaller/bigger)

(function(){
  $('button').on('click', function(e){
    $('#test').slideToggle();
  });
})();
		@media screen and (min-width: 1000px) {
			ul {
				height:50px;
				background-color: red;
				width: 100%;
			}
			li {

				display: inline-block;
				height: 50px;
				line-height: 50px;
				float:left;
				margin-left: 50px;
			}
			#test {
				display: block !important;
			}
			button {

				display: none !important;
			}
		}

		@media screen and (max-width: 1000px) {
			ul {
				background-color: red;
				width: 100%;
			}
			li {
				display: block;
				height: 50px;
				line-height: 50px;
			}
			#test {
				display: none;
			}
			button {
				display: block;
			}
		}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="test">
	<ul>
		<li>This</li>
		<li>Is</li>
		<li>a</li>
		<li>menu</li>
	</ul>
</div>
<button >Toggle menu</button>

相关问答

更多
  • 要回答这个问题,我可以覆盖inline-css吗? ... 是的 ,通过使用!important 。 你真正的问题: 当屏幕再次变大时,通过向媒体查询添加!important。 请参阅以下代码段(全屏运行并使屏幕更小/更大) (function(){ $('button').on('click', function(e){ $('#test').slideToggle(); }); })(); @media screen and (min-width: 1000px) { ...
  • 我同意Birdman,你应该考虑采用移动第一种方法。 然而,移动首先意味着最小的设备尺寸完全在任何媒体查询之外。 下一个尺寸将开始第一个媒体查询。 你只需要一个最小宽度,因为这些新样式除了基本样式之外,不会覆盖它们。 创建的每个媒体查询都将继续与已调用的媒体查询相结合。 而不必担心iPad或平板电脑......担心您的设计元素何时开始变得不好看。 所有主流浏览器都有足够智能的仿真器来测试不同的设备尺寸。 这里有一篇关于利弊的好文章。 我总是先编码移动,并且从不担心样式碰撞,除非我故意这样做:) https: ...
  • 简单的答案是,在CSS3中允许嵌套@media规则(而不仅仅是媒体查询)时,在CSS2.1中不允许嵌套规则(主要是因为没有理由允许它看到媒体查询还没有存在。 Firefox是第一个支持嵌套@media规则的人,但是自从第一次发布此回答以来,其他浏览器都慢慢赶上了。 也就是说,Chrome(和类似地,Blink Opera)已经被更新以支持它。 据我所知,Safari和IE仍然不支持它。 有一些术语混淆需要清理,以便我们了解究竟发生了什么。 您所参考的代码是@media规则,而不是太多的媒体查询 - 媒体查询 ...
  • CSS媒体查询重叠的规则是什么? 级联。 @media规则对于级联是透明的,因此当两个或多个@media规则同时匹配时,浏览器应该在所有匹配的规则中应用样式,并相应地解析级联。 1 在所有支持浏览器中,将会发生什么,正好20em和45em? 完全20em宽,您的第一个和第二个媒体查询都会匹配。 浏览器将在@media规则和级联中应用样式,因此如果有任何冲突的规则需要被覆盖,则最后声明的规则将胜出(占用特定选择器, !important等等)。 同样对于第二和第三个媒体查询,当视口正好是45em宽。 考虑到您 ...
  • 您的测试证明它应该如何工作 。 在您的示例中,当浏览器的宽度小于960px 且小于700px时,两个查询都将被视为true。 这是按预期工作的,事实上,我是如何在多个站点上实现响应式设计的,每个查询都是一个新的断点,表明事物如何优雅地降级为小型。 Your tests prove true how it should work. In your example, when the width of the browser is less than 960px and less than 700px, bot ...
  • 您不必在第二行再次添加@media。 这应该工作: @media screen and (min-width: 768px) and (max-width: 990px), screen and (max-width: 630px) { .community-info-box { width: 100%; margin-right: 0; float: none; ... : ... } } You don't have to ...
  • 虽然这不是一个很好的解决方案,但您可以做的是为某个目标元素设置content属性。 @media ... #target { content: "sidebar-open"; } 由于元素不是:before或:after ,因此内容将计算为none以进行渲染,但您仍然可以使用Javascript读取该值: $('#target').css('content'); //"sidebar-open" While this isn't a nice solution, what ...
  • 最大宽度是这些样式显示的最大宽度。 比指定号码宽的屏幕不会使用与该规则相关联的样式。 同样,最小宽度是显示这些样式的最小宽度。 比指定号码窄的屏幕不会使用与该规则关联的样式。 我已经改变了你的代码与max-width现在它的工作罚款所有媒体查询,只是调整浏览器 @media ( min-width : 1200px) { .color{ color: blue; } } @media ( max-width : 992px) { .color{ color: ...
  • 你的代码有一些错误,缺少$ in $devices变量。 您编写@include screen-width("mobile")但移动设备不在设备列表中。 在$media变量中, max-width必须是一个字符串,然后您必须使用插值来添加@media规则。 在@each循环中的比较是错误的,但我暂时没有解决这个问题。 此代码有效: $devices: ("sphone","phone","tablet") $breakpoints: ( width2: ('sphone' : 320, 'phone' : ...
  • 好的,这个问题是由一个过渡引起的: .slides .slide { -webkit-transition: width 0.6s cubic-bezier(0.6, 0.65, 0.52, 0.97); transition: width 0.6s cubic-bezier(0.6, 0.65, 0.52, 0.97); } 宽度的变化实际上触发了这个转换,它在生成打印视图时被冻结。 删除过渡后,一切运作良好。 然而,这种转换不应该运行,因为它在print媒体查询中。 我已经向Chromium提 ...

相关文章

更多

最新问答

更多
  • h2元素推动其他h2和div。(h2 element pushing other h2 and div down. two divs, two headers, and they're wrapped within a parent div)
  • 创建一个功能(Create a function)
  • 我投了份简历,是电脑编程方面的学徒,面试时说要培训三个月,前面
  • PDO语句不显示获取的结果(PDOstatement not displaying fetched results)
  • Qt冻结循环的原因?(Qt freezing cause of the loop?)
  • TableView重复youtube-api结果(TableView Repeating youtube-api result)
  • 如何使用自由职业者帐户登录我的php网站?(How can I login into my php website using freelancer account? [closed])
  • SQL Server 2014版本支持的最大数据库数(Maximum number of databases supported by SQL Server 2014 editions)
  • 我如何获得DynamicJasper 3.1.2(或更高版本)的Maven仓库?(How do I get the maven repository for DynamicJasper 3.1.2 (or higher)?)
  • 以编程方式创建UITableView(Creating a UITableView Programmatically)
  • 如何打破按钮上的生命周期循环(How to break do-while loop on button)
  • C#使用EF访问MVC上的部分类的自定义属性(C# access custom attributes of a partial class on MVC with EF)
  • 如何获得facebook app的publish_stream权限?(How to get publish_stream permissions for facebook app?)
  • 如何防止调用冗余函数的postgres视图(how to prevent postgres views calling redundant functions)
  • Sql Server在欧洲获取当前日期时间(Sql Server get current date time in Europe)
  • 设置kotlin扩展名(Setting a kotlin extension)
  • 如何并排放置两个元件?(How to position two elements side by side?)
  • 如何在vim中启用python3?(How to enable python3 in vim?)
  • 在MySQL和/或多列中使用多个表用于Rails应用程序(Using multiple tables in MySQL and/or multiple columns for a Rails application)
  • 如何隐藏谷歌地图上的登录按钮?(How to hide the Sign in button from Google maps?)
  • Mysql左连接旋转90°表(Mysql Left join rotate 90° table)
  • dedecms如何安装?
  • 在哪儿学计算机最好?
  • 学php哪个的书 最好,本人菜鸟
  • 触摸时不要突出显示表格视图行(Do not highlight table view row when touched)
  • 如何覆盖错误堆栈getter(How to override Error stack getter)
  • 带有ImageMagick和许多图像的GIF动画(GIF animation with ImageMagick and many images)
  • USSD INTERFACE - > java web应用程序通信(USSD INTERFACE -> java web app communication)
  • 电脑高中毕业学习去哪里培训
  • 正则表达式验证SMTP响应(Regex to validate SMTP Responses)