我可以将文件读取为bytes数组
但是当我将它转换为字符串时
它将utf16字节视为ascii
如何正确转换?
package main
import ("fmt"
"os"
"bufio"
)
func main(){
// read whole the file
f, err := os.Open("test.txt")
if err != nil {
fmt.Printf("error opening file: %v\n",err)
os.Exit(1)
}
r := bufio.NewReader(f)
var s,b,e = r.ReadLine()
if e==nil{
fmt.Println(b)
fmt.Println(s)
fmt.Println(string(s))
}
}
Run Code Online (Sandbox Code Playgroud)
输出:
假
[255 254 91 0 83 0 99 0 114 0 105 0 112 0 116 0 32 0 73 0 110 0 102 0 111 0 93 0 13 0]
S …
我想在svg中添加一个新行,当按下添加按钮时,应该在svg中添加一个新行我可以确定该行添加在元素中,但为什么它不显示在屏幕上?
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
#map
{
border:1px solid #000;
}
line
{
stroke:rgb(0,0,0);
stroke-width:3;
}
</style>
<script src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
<script type="text/javascript">
jQuery(document).ready(function(){
$("#add").click(function(){
var newLine=$('<line id="line2" x1="0" y1="0" x2="300" y2="300" />');
$("#map").append(newLine);
});
})
</script>
</head>
<body>
<h2 id="status">
0, 0
</h2>
<svg id="map" width="800" height="600" version="1.1" xmlns="http://www.w3.org/2000/svg">
<line id="line" x1="50" y1="0" x2="200" y2="300"/>
</svg>
<button id="add">add</button>
</body>
</html>
Run Code Online (Sandbox Code Playgroud) all is not a built-in function or keyword, but why can I not call a function if it is named all?
There is no error message in the debug console, and the function works if I rename it to all2.
Here is the code: tested in chrome and IE10
<!DOCTYPE html>
<head>
</head>
<body>
<script>
function all()
{
alert(1);
}
function all2()
{
alert(2);
}
</script>
<input type="button" value="all1" onclick="all()">
<input type="button" value="all2" onclick="all2()">
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
我想将一个arraylist存储到磁盘,所以我使用gson将其转换为字符串
ArrayList<Animal> anim=new ArrayList<Animal>();
Cat c=new Cat();
Dog d=new Dog();
c.parentName="I am animal C";
c.subNameC="I am cat";
d.parentName="I am animal D";
d.subNameD="I am dog";
anim.add(c);
anim.add(d);
Gson gson=new Gson();
String json=gson.toJson(anim);
public class Animal {
public String parentName;
}
public class Cat extends Animal{
public String subNameC;
}
public class Dog extends Animal{
public String subNameD;
}
Run Code Online (Sandbox Code Playgroud)
输出字符串:
[{"subNameC":"I am cat","parentName":"I am animal C"},{"subNameD":"I am dog","parentName":"I am animal D"}]
Run Code Online (Sandbox Code Playgroud)
现在我想用这个字符串转换回arraylist
我知道我应该使用类似的东西:
ArrayList<Animal> anim = gson.fromJson(json, ArrayList<Animal>.class);
Run Code Online (Sandbox Code Playgroud)
但这是不正确的,正确的语法是什么?
我正在使用Spring MVC 4.1.4
我有一些全局设置可以在整个应用程序中共享
只应在启动服务器时加载这些设置
我知道我可以使用context-param
<context-param>
<param-name>configA</param-name>
<param-value>valueA</param-value>
</context-param>
<context-param>
<param-name>configB</param-name>
<param-value>valueB</param-value>
</context-param>
Run Code Online (Sandbox Code Playgroud)
但我希望存储一些复杂的对象,就像这样
HashMap myConfig = new HashMap();
String[] cfgB={"b1", "b2"};
HashMap<String, String> cfgC=new HashMap<String, String>();
cfgC.put("C1", "1");
cfgC.put("C2", "2");
MyConfigD cfgD = new MyConfigD();
myConfig.put("configA", "A");
myConfig.put("configB",cfgB);
myConfig.put("configC",cfgC);
myConfig.put("configD",cfgD);
Run Code Online (Sandbox Code Playgroud)
context-param不可能这样做,我还可以在Java或Spring中使用什么?
这是我的Torch应用程序:
final Camera.Parameters p;
Camera camera=Camera.open();
camera.setPreviewTexture(new SurfaceTexture(0));
p = camera.getParameters();
p.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
camera.setParameters(p);
camera.startPreview();
Run Code Online (Sandbox Code Playgroud)
当我的应用程序运行时,某些设备无法检测到NFC标签.我注意到这种情况发生在Nexus 5X上,特别是.
当相机运行时,某些设备似乎无法检测到NFC.
可以通过编程方式解决这个问题吗?
现在我用它来创建一个元素
<!-- language: lang-java -->
Document doc = Jsoup.parseBodyFragment("<ol></ol>");
Elements ols=doc.getElementsByTag("ol");
Element ol=ols.get(0);
Run Code Online (Sandbox Code Playgroud)
但这太复杂了,因为我在程序中创建了很多dom,如果每次使用三行来创建一个元素,那就不方便了.
我可以在不使用文档和元素的情况下创建元素吗?
像这样:
<!-- language: lang-js -->
var ol=$('<ol></ol>');
Run Code Online (Sandbox Code Playgroud) 我有两个按钮,它们的形状相同,只是颜色不同
b1.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="10dp" />
<stroke android:width="5px" android:color="#000000" />
<solid
android:color="#ff0000"/>
</shape>
Run Code Online (Sandbox Code Playgroud)
b2.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="10dp" />
<stroke android:width="5px" android:color="#000000" />
<solid
android:color="#00ff00"/>
</shape>
Run Code Online (Sandbox Code Playgroud)
布局文件
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/b1"
android:text="B1" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/b2"
android:text="B2" />
Run Code Online (Sandbox Code Playgroud)
如果我想创建 100 个不同颜色的按钮,我需要创建 100 个可绘制的 xml。
我可以只创建一个可绘制的 xml,然后覆盖布局 xml 中的颜色或其他属性吗?
我找到了扩展通知面板的方法
Object sbservice = getSystemService("statusbar");
Class<?> statusbarManager = Class.forName("android.app.StatusBarManager");
Method showsb;
if (Build.VERSION.SDK_INT >= 17) {
showsb = statusbarManager.getMethod("expandNotificationsPanel");
} else {
showsb = statusbarManager.getMethod("expand");
}
showsb.invoke(sbservice);
Run Code Online (Sandbox Code Playgroud)
查看源代码后,我还找到了collapsePanels方法来折叠通知
但我找不到任何方法来检测通知面板状态
因为我想检查它是打开还是关闭,然后决定我应该打开它还是关闭它
我怎样才能知道这个状态?
我的程序目的:触发服务中的 BACK 按钮
我尝试了很多方法,没有人能达到这个目的,最后我发现了AccessibilityService,它可能是实现这个功能的最可能的方法。
我创建了这个 AccessibilityService,并测试了它的工作
package com.accessibilityservice;
public class MyAccessibilityService extends AccessibilityService {
public MyAccessibilityService() {
}
@Override
public void onAccessibilityEvent(AccessibilityEvent event) {
performGlobalAction(AccessibilityService.GLOBAL_ACTION_BACK);
}
@Override
public void onInterrupt() {
}
}
<?xml version="1.0" encoding="utf-8"?>
<accessibility-service xmlns:android="http://schemas.android.com/apk/res/android"
android:accessibilityEventTypes="typeAllMask"
android:accessibilityFeedbackType="feedbackSpoken"
android:accessibilityFlags="flagDefault"
android:canRetrieveWindowContent="true"
android:description="desc"
android:notificationTimeout="100"
android:settingsActivity="com.example.android.accessibility.ServiceSettingsActivity" />
Run Code Online (Sandbox Code Playgroud)
然后我尝试转向performGlobalAction服务,但它没有执行该操作。
public class MyService extends Service {
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
MyAccessibilityService mas=new MyAccessibilityService();
mas.performGlobalAction(AccessibilityService.GLOBAL_ACTION_BACK);
}
}
Run Code Online (Sandbox Code Playgroud)
我还尝试以不同的方式发送自定义事件,但没有人可以发送到 MyAccessibilityService
@Override
public int onStartCommand(Intent intent, int flags, …Run Code Online (Sandbox Code Playgroud) android accessibility-api android-service accessibilityservice android-accessibility